Class: Opto::Model::AttributeCollection
- Inherits:
-
Object
- Object
- Opto::Model::AttributeCollection
- Extended by:
- Forwardable
- Defined in:
- lib/opto/model/attribute_collection.rb
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#members ⇒ Object
readonly
Returns the value of attribute members.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #build_member(definition) ⇒ Object
- #build_members(definitions) ⇒ Object
- #errors ⇒ Object
-
#initialize(attribute_definitions = []) ⇒ AttributeCollection
constructor
A new instance of AttributeCollection.
- #inspect ⇒ Object
Constructor Details
#initialize(attribute_definitions = []) ⇒ AttributeCollection
Returns a new instance of AttributeCollection.
13 14 15 16 17 18 |
# File 'lib/opto/model/attribute_collection.rb', line 13 def initialize(attribute_definitions = []) @members = {} @group = Opto::Group.new build_members(attribute_definitions) end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
11 12 13 |
# File 'lib/opto/model/attribute_collection.rb', line 11 def group @group end |
#members ⇒ Object (readonly)
Returns the value of attribute members.
10 11 12 |
# File 'lib/opto/model/attribute_collection.rb', line 10 def members @members end |
Instance Method Details
#[](name) ⇒ Object
27 28 29 |
# File 'lib/opto/model/attribute_collection.rb', line 27 def [](name) members[name] end |
#build_member(definition) ⇒ Object
31 32 33 |
# File 'lib/opto/model/attribute_collection.rb', line 31 def build_member(definition) members[definition[:name]] = Attribute.new(self, definition, group.build_option(definition)) end |
#build_members(definitions) ⇒ Object
35 36 37 |
# File 'lib/opto/model/attribute_collection.rb', line 35 def build_members(definitions) definitions.each { |definition| build_member(definition) } end |
#errors ⇒ Object
39 40 41 |
# File 'lib/opto/model/attribute_collection.rb', line 39 def errors Hash[*group.errors.flat_map { |k,v| [k.to_sym, v] }] end |
#inspect ⇒ Object
20 21 22 23 24 25 |
# File 'lib/opto/model/attribute_collection.rb', line 20 def inspect string = "#<#{self.class.name}:#{self.object_id} " string << "members: #{members.keys.inspect}" string << ">" string end |