Class: Docka::Util::Config
- Inherits:
-
Object
- Object
- Docka::Util::Config
- Defined in:
- lib/docka/util/config.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
Instance Method Summary collapse
- #current_data ⇒ Object
- #get(*args, &block) ⇒ Object
-
#initialize(data, pos) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(data, pos) ⇒ Config
Returns a new instance of Config.
6 7 8 9 |
# File 'lib/docka/util/config.rb', line 6 def initialize(data, pos) @data = data @pos = pos end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
11 12 13 |
# File 'lib/docka/util/config.rb', line 11 def data @data end |
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
11 12 13 |
# File 'lib/docka/util/config.rb', line 11 def pos @pos end |
Instance Method Details
#current_data ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/docka/util/config.rb', line 13 def current_data @current_data ||= begin data = self.data pos.each{|i| data = data[i]} data end end |
#get(*args, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/docka/util/config.rb', line 21 def get(*args, &block) = args. v = current_data pos = self.pos.dup args.each do |key| key = key.to_s pos << key v = v[key] raise ::Docka::NotConfiguredError.new(pos.join('.')) if !v && [:optional] == false end block ? block.call(self.class.new(data, pos)) : v end |