class Configurator

Constants

VERSION

Attributes

params[RW]

Public Class Methods

load( source ) click to toggle source

Creates a Configurator object and loads parameters from given file or a Hash.

Returns a created object with parameters loaded into it.

# File lib/aerogel/configurator/configurator.rb, line 52
def self.load( source )
  config = self.new source
  return config
end
new( source = nil ) click to toggle source

Creates a Configurator object and loads parameters from optionally provided source. source is either a String which is treated as a name of config file or a Hash

# File lib/aerogel/configurator/configurator.rb, line 11
def initialize( source = nil )
  @params = {}
  load source unless source.nil?
end

Public Instance Methods

clear!() click to toggle source

Clears parameters

# File lib/aerogel/configurator/configurator.rb, line 44
def clear!
  @params = {}
end
load( source ) click to toggle source

Loads parameters from source. source is either a String which is treated as a name of config file or a Hash

# File lib/aerogel/configurator/configurator.rb, line 30
def load( source )
  if source.is_a? String
    filename_contents = File.read source
    DSL.new( filename_contents, @params )
  elsif source.is_a? Hash
    deep_merge( @params, source)
  else
    raise ArgumentError.new("Invalid source passed to #load method")
  end
  true
end
method_missing(method, *args, &block) click to toggle source
# File lib/aerogel/configurator/configurator.rb, line 17
def method_missing(method, *args, &block)
  # puts "Configurator.method_missing: #{method}"
  Parameter.new( @params ).send method, *args, &block
end
respond_to?(method, include_private = false) click to toggle source
Calls superclass method
# File lib/aerogel/configurator/configurator.rb, line 22
def respond_to?(method, include_private = false)
  super || (Parameter.new( @params ).respond_to? method, include_private)
end

Private Instance Methods

deep_merge( left, right ) click to toggle source

Deep merge parameters hash with other hash.

# File lib/aerogel/configurator/configurator.rb, line 61
def deep_merge( left, right )
  right.each do |key, value|
    if value.is_a? Hash
      left[key] ||= {}
      deep_merge( left[key], right[key] )
    else
      left[key] = right[key]
    end
  end
end