module Config

Constants

VERSION

Public Class Methods

load_and_set_nested_settings(base_path, default_file_name) click to toggle source
# File lib/config.rb, line 57
def self.load_and_set_nested_settings(base_path, default_file_name)
  Kernel.send(:remove_const, Config.const_name) if Kernel.const_defined?(Config.const_name)

  config = Options.new
  config.add_source!(File.join(base_path, default_file_name).to_s)
  #config.add_source!(File.join(base_path, priority_file_name).to_s)

  folder_names = Dir.glob("#{base_path}/**/**").select {|f| File.directory? f}

  folder_names.each do |folder_name|
    namespace_path = folder_name.to_s.sub("#{base_path.to_s}/", "")
    namespaces = namespace_path.split("/")

    namespaces.each_with_index do |namespace, i|
      path = namespaces.first(i + 1).join("/")
      namespaced_default_file = File.join(base_path, path, default_file_name).to_s
      #priority_default_file = File.join(base_path, path, priority_file_name).to_s

      config.add_source!(namespaced_default_file.to_s, path)
      #config.add_source!(priority_default_file.to_s, path)
    end
  end

  config.load!
  config.load_env! if @@use_env

  Kernel.const_set(Config.const_name, config)
end
load_and_set_settings(*files) click to toggle source

Loads and sets the settings constant!

# File lib/config.rb, line 52
def self.load_and_set_settings(*files)
  Kernel.send(:remove_const, Config.const_name) if Kernel.const_defined?(Config.const_name)
  Kernel.const_set(Config.const_name, Config.load_files(files))
end
load_files(*files) 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 38
def self.load_files(*files)
  config = Options.new

  # add settings sources
  [files].flatten.compact.uniq.each do |file|
    config.add_source!(file.to_s)
  end

  config.load!
  config.load_env! if @@use_env
  config
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
      root = Padrino.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 98
def self.reload!
  Kernel.const_get(Config.const_name).reload!
end
setting_files(config_root, env) click to toggle source
# File lib/config.rb, line 86
def self.setting_files(config_root, env)
  [
    File.join(config_root, "settings.yml").to_s,
    File.join(config_root, "settings", "#{env}.yml").to_s,
    File.join(config_root, "environments", "#{env}.yml").to_s,

    File.join(config_root, "settings.local.yml").to_s,
    File.join(config_root, "settings", "#{env}.local.yml").to_s,
    File.join(config_root, "environments", "#{env}.local.yml").to_s
  ].freeze
end
setup() { |self| ... } click to toggle source
# File lib/config.rb, line 31
def self.setup
  yield self if @@_ran_once == false
  @@_ran_once = true
end