module Config
Constants
- VERSION
Public Class Methods
Source
# File lib/config.rb, line 58 def self.load_and_set_settings(*sources) name = Config.const_name Object.send(:remove_const, name) if Object.const_defined?(name) # Include extra sources in the loading process all_sources = [sources, Config.extra_sources].flatten.compact Object.const_set(name, Config.load_files(*all_sources)) end
Loads and sets the settings constant!
Source
# File lib/config.rb, line 43 def self.load_files(*sources) config = Options.new # add settings sources [sources].flatten.compact.each do |source| config.add_source!(source) end config.add_source!(Sources::EnvSource.new(ENV)) if Config.use_env config.load! config end
Create a populated Options
instance from a settings file. If a second file is given, then the sections of that file will overwrite existing sections of the first file.
Source
# File lib/config.rb, line 76 def self.local_setting_files(config_root, env) [ (File.join(config_root, "#{Config.file_name}.local.yml").to_s if env != 'test'), File.join(config_root, Config.dir_name, "#{env}.local.yml").to_s, File.join(config_root, 'environments', "#{env}.local.yml").to_s ].compact end
Source
# File lib/config/integrations/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 if Padrino.respond_to?(:env) root = Padrino.root if Padrino.respond_to?(:root) end Config.load_and_set_settings(Config.setting_files(File.join(root, 'config'), env)) inner_app.use(::Config::Rack::Reloader) if inner_app.development? end end
provide helper to register within your Sinatra app
set :root, File.dirname(__FILE__) register Config
Source
# File lib/config.rb, line 84 def self.reload! Object.const_get(Config.const_name).reload! end
Source
# File lib/config.rb, line 67 def self.setting_files(config_root, env) [ File.join(config_root, "#{Config.file_name}.yml").to_s, File.join(config_root, Config.dir_name, "#{env}.yml").to_s, File.join(config_root, 'environments', "#{env}.yml").to_s, *local_setting_files(config_root, env) ].freeze end
Source
# File lib/config.rb, line 36 def self.setup yield self unless @_ran_once @_ran_once = true end