class JunglePath::Config::Configuration

replacement for configatron gem.

Attributes

lock[RW]

Public Class Methods

new(parent=nil) click to toggle source
# File lib/jungle_path/config.rb, line 10
def initialize(parent=nil)
  @parent = parent
  @hash = {}
  @lock = false
end

Public Instance Methods

is_locked?() click to toggle source
# File lib/jungle_path/config.rb, line 16
def is_locked?
  return true if @lock
  return @parent.lock if @parent
  @lock
end
method_missing(m, *args, &block) click to toggle source
# File lib/jungle_path/config.rb, line 22
def method_missing(m, *args, &block)
  s = m.to_s
  return_value = nil
  if s.end_with? "="
    key = s[0..-2]
    if is_locked?
      raise "Configuration '#{key}' is locked."
    else
      @hash[key] = args[0]
    end
  else
    key = s
    if @hash.include?(key)
      return_value = @hash[key]
    else
      if is_locked?
        return_value = nil
      else
        return_value = Configuration.new self
        @hash[key] = return_value
      end
    end
  end
  return_value
end