Sha256: 52d9efd53f0dd6b08aac7f66f39ea46169b1b8c687f6446517b3a99104050e9b

Contents?: true

Size: 1.35 KB

Versions: 11

Compression:

Stored size: 1.35 KB

Contents

require 'active_support/core_ext/module/attribute_accessors'
require 'rails_config/options'

require "rails_config/sources/yaml_source"

require 'rails_config/vendor/deep_merge' unless defined?(DeepMerge)

module RailsConfig
  # ensures the setup only gets run once
  @@_ran_once = false

  mattr_accessor :const_name
  @@const_name = "Settings"

  def self.setup
    yield self if @@_ran_once == false
    @@_ran_once = true
  end

  # 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.
  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

  # Loads and sets the settings constant!
  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

  def self.reload!
    Kernel.const_get(RailsConfig.const_name).reload!
  end
end

# add rails integration
require('rails_config/integration/rails') if defined?(::Rails)

# add sinatra integration
require('rails_config/integration/sinatra') if defined?(::Sinatra)

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rails_config-0.3.4 lib/rails_config.rb
rails_config-0.3.3 lib/rails_config.rb
rails_config-0.3.2 lib/rails_config.rb
rails_config-0.3.1 lib/rails_config.rb
rails_config-0.3.0 lib/rails_config.rb
rails_config-0.2.7 lib/rails_config.rb
rails_config-0.2.6 lib/rails_config.rb
rails_config-0.2.5 lib/rails_config.rb
rails_config-0.2.4 lib/rails_config.rb
rails_config-0.2.3 lib/rails_config.rb
rails_config-0.2.2 lib/rails_config.rb