Sha256: fdc00dfd2a3ed815e95de0d888e26cc0dc6cef4f6b1dd9267e5c3289561d8f98

Contents?: true

Size: 820 Bytes

Versions: 2

Compression:

Stored size: 820 Bytes

Contents

module ConfigLoader
  
  class Map < Hash
    
    attr_reader :file_name, :running_env, :project_root

    def initialize(file_name, running_env, project_root)
      raise MissingConfigFileNameError unless file_name
      @file_name    = "#{file_name}.yml"
      @running_env  = running_env
      @project_root = project_root
    end
    
    def file_content
      raise MissingConfigFileError unless File.exists?(full_file_name)
      File.open(full_file_name) { |file| YAML::load(file) }
    end
    
    def full_file_name
      "#{project_root}/config/#{file_name}"
    end
    
    def populate
      file_content[@running_env].each do |key, value|
        self[key] = value
        self[key.to_sym] = value
      end
    end
    
    def method_missing(method_name)
      self[method_name]
    end

  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
configloader-0.1.1 lib/config_loader/map.rb
configloader-0.1.0 lib/config_loader/map.rb