Module: Scrivito::AttributeContent

Included in:
BasicObj, BasicWidget
Defined in:
lib/scrivito/attribute_content.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



75
76
77
78
# File 'lib/scrivito/attribute_content.rb', line 75

def method_missing(method_name, *args)
  attribute_name = method_name.to_s
  has_custom_attribute?(attribute_name) ? read_attribute(attribute_name) : super
end

Instance Method Details

#[](attribute_name) ⇒ Object

Returns the value of an attribute specified by its name. Passing an invalid key will not raise an error, but return nil.

Parameters:

  • attribute_name (Symbol, String)

    the name of the attribute.

Returns:

  • the value of the attribute if it defined or nil otherwise.



88
89
90
91
# File 'lib/scrivito/attribute_content.rb', line 88

def [](attribute_name)
  attribute_name = attribute_name.to_s
  read_attribute(attribute_name) if has_attribute?(attribute_name)
end

#obj_classScrivito::ObjClass?

Deprecated.

Returns the obj class of this object.

Returns:

See Also:



166
167
168
169
170
171
172
173
174
175
# File 'lib/scrivito/attribute_content.rb', line 166

def obj_class
  if revision.workspace.uses_obj_classes
    if obj_class_data = CmsBackend.instance.find_obj_class_data_by_name(revision, obj_class_name)
      ObjClass.new(obj_class_data, revision.workspace)
    end
  else
    Scrivito.print_obj_class_deprecated_warning
    nil
  end
end

#obj_class_nameString

Returns the obj class name of this object.

Returns:

  • (String)


152
153
154
# File 'lib/scrivito/attribute_content.rb', line 152

def obj_class_name
  data_from_cms.value_of('_obj_class')
end

#valid_widget_classes_for(field_name) ⇒ nil, Array<Symbol, String, Class>

Hook method to control which widget classes should be available for this page or widget. Override it to allow only certain classes or none. Must return either NilClass, or Array.

If nil is returned (default), then all widget classes will be available for this page or widget.

If an Array is returned, then it should include the desired classes. Each class must be either a String, a Symbol or the Class itself. Only these classes will be available and their order will be preserved.

Parameters:

  • field_name (String)

    Name of the widget field.

Returns:

  • (nil, Array<Symbol, String, Class>)


108
109
# File 'lib/scrivito/attribute_content.rb', line 108

def valid_widget_classes_for(field_name)
end