Sha256: 51064b40b4e4e1dfc9ab2cb9d0d71998a6ae885bba8495ba95121af5b5c994fa

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

require "rock_config/version"
require "rock_config/errors"
require "rock_config/environment_detector"
require "rock_config/configuration"
require "rock_config/manager"
require "rock_config/scanner"
require "rock_config/yaml_loader"
require "rock_config/config"

module RockConfig
  class << self
    def for(config_name, environment = detect_environment)
      manager.fetch(config_name, environment)
    end

    def configure
      yield configuration if block_given?
      @manager = nil
    end

    private

    def detect_environment
      @detected_environment ||= lambda do
        detector = EnvironmentDetector.new(ENV)
        detector.detect
      end.call
    end

    def configuration
      @configuration ||= initialize_configuration
    end

    def initialize_configuration
      configuration = Configuration.new

      configuration.scanned_directories << File.join(Dir.pwd, "config")
      configuration.config_loaders << YamlLoader.new

      configuration
    end

    def manager
      @manager ||= Manager.new(configuration)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rock_config-0.0.4 lib/rock_config.rb
rock_config-0.0.3 lib/rock_config.rb
rock_config-0.0.2 lib/rock_config.rb