Class: Scrivito::Attribute Deprecated

Inherits:
Object
  • Object
show all
Defined in:
lib/scrivito/attribute.rb

Overview

Deprecated.

This class represents a CMS attribute. Attributes can be created, updated, deleted and all attribute properties can be read. Attributes are part of an ObjClass and therefore each attribute belongs to exactly one ObjClass. Most of the operations interact with the currently selected Workspace. Operations like create, destroy and update need to be performed in the “rtc” workspace.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties) ⇒ Scrivito::Attribute

Deprecated.

Initializes a new attribute.

This allows you to set the different properties of an attribute by providing a Hash with the property names as keys and the values you want to set as values.

Examples:

Create a new attribute with name “locale” and type “string”.

Attribute.new(name: 'locale', type: :string)

Create a new “enum” attribute named “category” and provide values.

Attribute.new(name: 'category', type: :enum, values: %w(tech social))

Parameters:

  • properties (Hash)

Options Hash (properties):

  • :name (String)

    The name of the attribute.

  • :type (String)

    The type of the attribute, can be string, text, html, linklist, link, reference, referencelist, date, binary, widget, enum or multienum.

  • :values (Array<String>)

    Possible values if the type is either enum or multienum.

Raises:



35
36
37
38
39
# File 'lib/scrivito/attribute.rb', line 35

def initialize(properties)
  raise ScrivitoError, 'Please provide a hash of Attribute properties.' unless properties

  update_instance_properties(properties)
end

Instance Attribute Details

#obj_classScrivito::ObjClass

Deprecated.

Returns the obj class this attribute belongs to.

Returns:



70
71
72
# File 'lib/scrivito/attribute.rb', line 70

def obj_class
  @obj_class
end

Instance Method Details

#destroynil

Deprecated.

Destroys this attribute and persists the change in the CMS.

Examples:

Remove the “locale” attribute from the “Homepage” obj class.

ObjClass.find('Homepage').attributes['locale'].destroy

Returns:

  • (nil)


117
118
119
# File 'lib/scrivito/attribute.rb', line 117

def destroy
  Scrivito.raise_obj_class_deprecated_error
end

#nameString

Deprecated.

Returns the name of this attribute.

Returns:

  • (String)


45
46
47
# File 'lib/scrivito/attribute.rb', line 45

def name
  @name
end

#typeString

Deprecated.

Returns the type of this attribute. The type is either string, text, html, linklist, link, reference, referencelist, date, binary, widget, enum or multienum.

Returns:

  • (String)


54
55
56
# File 'lib/scrivito/attribute.rb', line 54

def type
  @type
end

#update(properties) ⇒ nil

Deprecated.

Updates this attribute and persists the changes in the CMS on its obj class. The obj_class and name of this attribute can not be updated.

See #initialize for a detailed overview of what properties are allowed and how to set them.

Examples:

Change the type of the “locale” attribute to “string”.

attribute = ObjClass.find('Homepage').attributes['locale']
attribute.update(type: :string)

Adding the value “sports” to the enum attribute “category” on the “Homepage” obj class.

attribute = ObjClass.find('Homepage').attributes['category']
attribute.update(values: attribute.values << 'sports')

Parameters:

  • properties (Hash)

Returns:

  • (nil)

Raises:



104
105
106
# File 'lib/scrivito/attribute.rb', line 104

def update(properties)
  Scrivito.raise_obj_class_deprecated_error
end

#valuesArray<String>

Deprecated.

Returns the values of this attribute, if it is of type enum or multienum.

Returns:

  • (Array<String>)

    values



62
63
64
# File 'lib/scrivito/attribute.rb', line 62

def values
  @values
end