Class: Docka::Util::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/docka/util/config.rb', line 11

def data
  @data
end

#posObject (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_dataObject



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)
  options = args.extract_options!
  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 && options[:optional] == false
  end
  block ? block.call(self.class.new(data, pos)) : v
end