Sha256: 41364cdba3cc1c9b9033313e983d67064f87fe6f1b7af76363ac2464525b44cc

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 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 ||= begin
                                  detector = EnvironmentDetector.new(ENV)
                                  detector.detect
                                end
    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.7 lib/rock_config.rb
rock_config-0.0.6 lib/rock_config.rb
rock_config-0.0.5 lib/rock_config.rb