Class: Scrivito::AttributeCollection Deprecated
- Inherits:
-
Object
- Object
- Scrivito::AttributeCollection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/scrivito/attribute_collection.rb
Overview
Deprecated.
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? deprecated Deprecated.
- #add(attribute) ⇒ Scrivito::AttributeCollection (also: #<<) deprecated Deprecated.
Instance Method Details
#[](name) ⇒ Scrivito::Attribute?
Deprecated.
Finds an attribute in this collection by its name.
41 42 43 |
# File 'lib/scrivito/attribute_collection.rb', line 41 def [](name) @attributes.detect { |attribute| attribute.name == name.to_s } end |
#add(attribute) ⇒ Scrivito::AttributeCollection Also known as: <<
Deprecated.
Adds an attribute to this collection and updates the obj class.
See ObjClass#attributes for example of how to add an attribute.
55 56 57 58 59 60 |
# File 'lib/scrivito/attribute_collection.rb', line 55 def add(attribute) attribute = Attribute.new(attribute) unless attribute.respond_to?(:to_cms_rest_api) @attributes << attribute @obj_class.update(attributes: @attributes) self end |