Class: Scrivito::AttributeCollection Deprecated

Inherits:
Object
  • Object
show all
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

Instance Method Details

#[](name) ⇒ Scrivito::Attribute?

Deprecated.

Finds an attribute in this collection by its name.

Parameters:

  • name (String)

    the name of the attribute

Returns:

  • (Scrivito::Attribute)

    if there is an attribute with name name

  • (nil)

    if there is no attribute with name name

See Also:



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.

Parameters:

  • attribute (Scrivito::Attribute, Hash)

    The attribute to add. Can be either an attribute instance or an attribute property hash.

Returns:



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