Sha256: 459f8fc21897e7d6a0ca763bcb3e981c83dcb918ca530aa3e9772daf81108390

Contents?: true

Size: 755 Bytes

Versions: 3

Compression:

Stored size: 755 Bytes

Contents

require 'erb'
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.new(full_file_name) unless File.exists?(full_file_name)
      YAML.load(ERB.new(File.read(full_file_name)).result)
    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

3 entries across 3 versions & 1 rubygems

Version Path
configloader-0.3.2 lib/config_loader/map.rb
configloader-0.3.1 lib/config_loader/map.rb
configloader-0.3.0 lib/config_loader/map.rb