Class: JunglePath::Config::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/jungle_path/config.rb

Overview

replacement for configatron gem.

Direct Known Subclasses

ConfigurationRoot

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ Configuration

Returns a new instance of Configuration.



10
11
12
13
14
# File 'lib/jungle_path/config.rb', line 10

def initialize(parent=nil)
  @parent = parent
  @hash = {}
  @lock = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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

Instance Attribute Details

#lockObject

Returns the value of attribute lock.



8
9
10
# File 'lib/jungle_path/config.rb', line 8

def lock
  @lock
end

Instance Method Details

#is_locked?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
# File 'lib/jungle_path/config.rb', line 16

def is_locked?
  return true if @lock
  return @parent.lock if @parent
  @lock
end