Module: RailsConfig
- Defined in:
- lib/rails_config/options.rb,
lib/rails_config/version.rb,
lib/rails_config/rails_config.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.3'
- @@_ran_once =
ensures the setup only gets run once
false
- @@options =
nil
- @@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.
- .method_missing(method, *args, &block) ⇒ Object
-
.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!
36 37 38 39 40 |
# File 'lib/rails_config/rails_config.rb', line 36 def self.load_and_set_settings(*files) Kernel.send(:remove_const, @@const_name) if Kernel.const_defined?(@@const_name) load_files(files) Kernel.const_set(@@const_name, self) 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.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rails_config/rails_config.rb', line 24 def self.load_files(*files) @@options = Options.new # add yaml sources [files].flatten.compact.uniq.each do |file| @@options.add_source!(file.to_s) end @@options.load! end |
.method_missing(method, *args, &block) ⇒ Object
46 47 48 |
# File 'lib/rails_config/rails_config.rb', line 46 def self.method_missing(method, *args, &block) (@@options[I18n.locale] || @@options[I18n.default_locale] || {}).send(method, *args) 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
42 43 44 |
# File 'lib/rails_config/rails_config.rb', line 42 def self.reload! @@options.reload! end |
.setup {|_self| ... } ⇒ Object
17 18 19 20 |
# File 'lib/rails_config/rails_config.rb', line 17 def self.setup yield self if @@_ran_once == false @@_ran_once = true end |