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.
5 6 7 8 |
# File 'lib/enumerize/attribute_map.rb', line 5 def initialize @attributes = {} @dependants = [] end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/enumerize/attribute_map.rb', line 3 def attributes @attributes end |
Instance Method Details
#<<(attr) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/enumerize/attribute_map.rb', line 14 def <<(attr) @attributes[attr.name.to_s] = attr @dependants.each do |dependant| dependant << attr end end |
#[](name) ⇒ Object
10 11 12 |
# File 'lib/enumerize/attribute_map.rb', line 10 def [](name) @attributes[name.to_s] end |
#add_dependant(dependant) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/enumerize/attribute_map.rb', line 31 def add_dependant(dependant) @dependants << dependant each do |attr| dependant << attr end end |
#each ⇒ Object
21 22 23 24 25 |
# File 'lib/enumerize/attribute_map.rb', line 21 def each @attributes.each_pair do |_name, attr| yield attr end end |
#empty? ⇒ Boolean
27 28 29 |
# File 'lib/enumerize/attribute_map.rb', line 27 def empty? @attributes.empty? end |