Module: RailsConfig
- Defined in:
- lib/rails_config.rb,
lib/rails_config/options.rb,
lib/rails_config/version.rb,
lib/rails_config/rack/reloader.rb,
lib/rails_config/integration/rails.rb,
lib/rails_config/integration/sinatra.rb,
lib/rails_config/sources/yaml_source.rb,
lib/generators/rails_config/install_generator.rb
Defined Under Namespace
Modules: Generators, Integration, Rack, Sources Classes: Options
Constant Summary collapse
- VERSION =
'0.3.1'
- @@_ran_once =
ensures the setup only gets run once
false
- @@const_name =
"Settings"
Class Method Summary collapse
-
.load_and_set_settings(*files) ⇒ Object
Loads and sets the settings constant!.
-
.load_files(*files) ⇒ Object
Create a populated Options instance from a yaml file.
-
.registered(app) ⇒ Object
provide helper to register within your Sinatra app.
- .reload! ⇒ Object
- .setup {|_self| ... } ⇒ Object
Class Method Details
.load_and_set_settings(*files) ⇒ Object
Loads and sets the settings constant!
35 36 37 38 |
# File 'lib/rails_config.rb', line 35 def self.load_and_set_settings(*files) Kernel.send(:remove_const, RailsConfig.const_name) if Kernel.const_defined?(RailsConfig.const_name) Kernel.const_set(RailsConfig.const_name, RailsConfig.load_files(files)) end |
.load_files(*files) ⇒ Object
Create a populated Options instance from a yaml file. If a second yaml file is given, then the sections of that file will overwrite the sections if the first file if they exist in the first file.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rails_config.rb', line 22 def self.load_files(*files) config = Options.new # add yaml sources [files].flatten.compact.uniq.each do |file| config.add_source!(file.to_s) end config.load! config end |
.registered(app) ⇒ Object
provide helper to register within your Sinatra app
set :root, File.dirname(__FILE__) register RailsConfig
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rails_config/integration/sinatra.rb', line 9 def self.registered(app) app.configure do |inner_app| env = inner_app.environment || ENV["RACK_ENV"] root = inner_app.root # use Padrino settings if applicable if defined?(Padrino) env = Padrino.env root = Padrino.root end RailsConfig.load_and_set_settings( File.join(root.to_s, "config", "settings.yml").to_s, File.join(root.to_s, "config", "settings", "#{env}.yml").to_s, File.join(root.to_s, "config", "environments", "#{env}.yml").to_s ) inner_app.use(::RailsConfig::Rack::Reloader) if inner_app.development? end end |
.reload! ⇒ Object
40 41 42 |
# File 'lib/rails_config.rb', line 40 def self.reload! Kernel.const_get(RailsConfig.const_name).reload! end |
.setup {|_self| ... } ⇒ Object
15 16 17 18 |
# File 'lib/rails_config.rb', line 15 def self.setup yield self if @@_ran_once == false @@_ran_once = true end |