Class: Enumerize::AttributeMap

Inherits:
Object
  • Object
show all
Defined in:
lib/enumerize/attribute_map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttributeMap

Returns a new instance of AttributeMap.



7
8
9
10
# File 'lib/enumerize/attribute_map.rb', line 7

def initialize
  @attributes = {}
  @dependants = []
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/enumerize/attribute_map.rb', line 5

def attributes
  @attributes
end

Instance Method Details

#<<(attr) ⇒ Object



16
17
18
19
20
21
# File 'lib/enumerize/attribute_map.rb', line 16

def <<(attr)
  @attributes[attr.name.to_s] = attr
  @dependants.each do |dependant|
    dependant << attr
  end
end

#[](name) ⇒ Object



12
13
14
# File 'lib/enumerize/attribute_map.rb', line 12

def [](name)
  @attributes[name.to_s]
end

#add_dependant(dependant) ⇒ Object



33
34
35
36
37
38
# File 'lib/enumerize/attribute_map.rb', line 33

def add_dependant(dependant)
  @dependants << dependant
  each do |attr|
    dependant << attr
  end
end

#eachObject



23
24
25
26
27
# File 'lib/enumerize/attribute_map.rb', line 23

def each
  @attributes.each_pair do |_name, attr|
    yield attr
  end
end

#empty?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/enumerize/attribute_map.rb', line 29

def empty?
  @attributes.empty?
end