Class: Configue::Criteria

Inherits:
Object
  • Object
show all
Defined in:
lib/configue/criteria.rb

Instance Method Summary collapse

Constructor Details

#initialize(container, *path) ⇒ Criteria

Returns a new instance of Criteria.



5
6
7
8
# File 'lib/configue/criteria.rb', line 5

def initialize(container, *path)
  @container = container
  @path = path
end

Instance Method Details

#[](key) ⇒ Object



10
11
12
# File 'lib/configue/criteria.rb', line 10

def [](key)
  self.class.new(@container, *@path, key.to_s)
end

#exist?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
# File 'lib/configue/criteria.rb', line 21

def exist?
  @path.each.inject(@container) do |h, key|
    return false unless h.respond_to?(:has_key?) and h.has_key?(key)
    h[key]
  end
  true
end

#retrieveObject



14
15
16
17
18
19
# File 'lib/configue/criteria.rb', line 14

def retrieve
  @path.each.inject(@container) do |h, key|
    return nil unless h.respond_to?(:has_key?) and h.has_key?(key)
    h[key]
  end
end