module Config

Constants

VERSION

Public Class Methods

load_and_set_settings(*sources) click to toggle source

Loads and sets the settings constant!

# File lib/config.rb, line 57
def self.load_and_set_settings(*sources)
  name = Config.const_name
  Object.send(:remove_const, name) if Object.const_defined?(name)
  Object.const_set(name, Config.load_files(sources))
end
load_files(*sources) click to toggle source

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.

# File lib/config.rb, line 42
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
local_setting_files(config_root, env) click to toggle source
# File lib/config.rb, line 72
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
registered(app) click to toggle source

provide helper to register within your Sinatra app

set :root, File.dirname(__FILE__) register Config

# 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
reload!() click to toggle source
# File lib/config.rb, line 80
def self.reload!
  Object.const_get(Config.const_name).reload!
end
setting_files(config_root, env) click to toggle source
# File lib/config.rb, line 63
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
setup() { |self| ... } click to toggle source
# File lib/config.rb, line 35
def self.setup
  yield self unless @_ran_once
  @_ran_once = true
end