Sha256: 1771200f11b6238a7e75f2e724ee6e9c5e16e6f3dad836e16afd6027ec01e908

Contents?: true

Size: 735 Bytes

Versions: 2

Compression:

Stored size: 735 Bytes

Contents

require 'yaml'

module ConfigLoader
  
  class Map
    
    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 load
      file_content[@running_env]
    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.2.2 lib/config_loader/map.rb
configloader-0.2.1 lib/config_loader/map.rb