Class: JunglePath::Config::Configuration
- Inherits:
-
Object
- Object
- JunglePath::Config::Configuration
- Defined in:
- lib/jungle_path/config.rb
Overview
replacement for configatron gem.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#lock ⇒ Object
Returns the value of attribute lock.
Instance Method Summary collapse
-
#initialize(parent = nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #is_locked? ⇒ Boolean
- #method_missing(m, *args, &block) ⇒ Object
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
#lock ⇒ Object
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
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 |