Class: Configurations::Maps::Properties

Inherits:
Object
  • Object
show all
Defined in:
lib/configurations/maps/properties.rb

Defined Under Namespace

Classes: Entry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reader = Readers::Tolerant.new) ⇒ Properties

Returns a new instance of Properties.



8
9
10
11
# File 'lib/configurations/maps/properties.rb', line 8

def initialize(reader = Readers::Tolerant.new)
  @map = {}
  @reader = reader
end

Instance Attribute Details

#mapObject (readonly)

Returns the value of attribute map.



4
5
6
# File 'lib/configurations/maps/properties.rb', line 4

def map
  @map
end

Instance Method Details

#add(properties) ⇒ Object



17
18
19
20
21
# File 'lib/configurations/maps/properties.rb', line 17

def add(properties)
  properties.each do |property|
    add_entry(property, @map)
  end
end

#add_entry(property, subtree) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/configurations/maps/properties.rb', line 31

def add_entry(property, subtree)
  if property.is_a?(Hash)
    property.each do |key, val|
      subtree[key] = add_entry(val, subtree.fetch(key, {}))
    end
  elsif property.is_a?(Array)
    property.each do |val|
      add_entry(val, subtree)
    end
  else
    subtree[property] = Entry.new
  end

  subtree
end

#configurable?(path) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/configurations/maps/properties.rb', line 27

def configurable?(path)
  !!@reader.read(@map, path)
end

#empty?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/configurations/maps/properties.rb', line 13

def empty?
  @map.empty?
end

#entries_at(path) ⇒ Object



23
24
25
# File 'lib/configurations/maps/properties.rb', line 23

def entries_at(path)
  @reader.read(@map, path) || {}
end