class Envyable::Loader
Internal: Loads yaml files into ENV (or a supplied hash).
Attributes
loadable[R]
Internal: Returns the Hash loadable of the loader
path[R]
Internal: Returns the String or Pathname path of the loader
Public Class Methods
new(path, loadable = ENV)
click to toggle source
Internal: initalize a Loader
path - a Pathname or String that describes where the yaml file
resides.
loadable - a Hash or hashlike structure that the yaml file variables
should be loaded into (default: ENV).
# File lib/envyable/loader.rb, line 16 def initialize(path, loadable = ENV) @path = path @loadable = loadable end
Public Instance Methods
load(environment = 'development')
click to toggle source
Internal: perform the loading from the given environment
environment - a String describing the environment from which to load the
variables (default: development).
Examples
load('production')
Returns nothing.
# File lib/envyable/loader.rb, line 31 def load(environment = 'development') if @yml ||= load_yml @yml.each { |key, value| set_value(key, value) } if @yml[environment] @yml[environment].each { |key, value| set_value(key, value) } end end end
Private Instance Methods
load_yml()
click to toggle source
# File lib/envyable/loader.rb, line 42 def load_yml yml_path = File.expand_path(@path) return nil unless File.exist?(yml_path) YAML.load_file(yml_path) end
set_value(key, value)
click to toggle source
# File lib/envyable/loader.rb, line 48 def set_value(key, value) @loadable[key.to_s] = value.to_s unless value.is_a?(Hash) end