Class: Enumerize::AttributeMap
- Inherits:
-
Object
- Object
- Enumerize::AttributeMap
- Defined in:
- lib/enumerize/attribute_map.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #<<(attr) ⇒ Object
- #[](name) ⇒ Object
- #add_dependant(dependant) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ AttributeMap
constructor
A new instance of AttributeMap.
Constructor Details
#initialize ⇒ AttributeMap
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
#attributes ⇒ Object (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 |
#each ⇒ Object
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
29 30 31 |
# File 'lib/enumerize/attribute_map.rb', line 29 def empty? @attributes.empty? end |