Class: Scrivito::AttributeCollection
- Inherits:
-
Object
- Object
- Scrivito::AttributeCollection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/scrivito/attribute_collection.rb
Overview
Represents a collection of Attribute instances. It provides convienient ways to find and add attributes and is returned by ObjClass#attributes. It behaves almost exactly as an Array, so methods like ‘#each`, `#select` etc. are available. It is not necessary to manually create an AttributeCollection, because a simple Array with attributes can be used instead.
Instance Method Summary collapse
-
#[](name) ⇒ Scrivito::Attribute?
Finds an attribute in this collection by its name.
-
#add(attribute) ⇒ Scrivito::AttributeCollection
(also: #<<)
Adds an attribute to this collection and updates the obj class.
Instance Method Details
#[](name) ⇒ Scrivito::Attribute?
Finds an attribute in this collection by its name.
38 39 40 |
# File 'lib/scrivito/attribute_collection.rb', line 38 def [](name) @attributes.detect { |attribute| attribute.name == name.to_s } end |
#add(attribute) ⇒ Scrivito::AttributeCollection Also known as: <<
Adds an attribute to this collection and updates the obj class.
See ObjClass#attributes for example of how to add an attribute.
51 52 53 54 55 56 |
# File 'lib/scrivito/attribute_collection.rb', line 51 def add(attribute) attribute = Attribute.new(attribute) unless attribute.respond_to?(:to_cms_rest_api) @attributes << attribute @obj_class.update(attributes: @attributes) self end |