Reputation: 3078
I've build a little rails development kit with development dependencies, generators and stuff for my personal use. I would like to be able to configure some things when loading the gem. An initializer is executed too late for gems like pry-rails.
So it would be cool to just use a configuration file in the project root. Though Rails is defined when my gem is loaded, Rails.root returns nil. How can I get the project root? It can be hackish and everything, it's just for some people.
This is my "initializer" which works great when absolutely addressing the config for one project:
class MyDevkit < MonkeyDevkit
# =======
# = Pry =
# =======
# disable pry components completely
#disable :pry
# do not make pry rails default console
#disable :pry, :console
# ========
# = Mail =
# ========
# disable mail components completely
#disable :mail
# disable letter opener
#disable :mail, :letter_opener
# ========
# = Misc =
# ========
#disable :rack_profiler
#disable :better_errors
#disable :quiet_assets
# comment to (temporary) disable the devkit completely
kitify!
end
Upvotes: 1
Views: 566
Reputation: 10630
can you try using Dir.getwd
to get current working directory (note: current working dir does not mean your gem's directory. it is a directory that ruby executable was called from), which should be same what you would get from Rails.root (unless some gem changes working dir)
Upvotes: 2