Module: Scrivito::AttributeContent
- Included in:
- BasicObj, BasicWidget
- Defined in:
- lib/scrivito/attribute_content.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#[](attribute_name) ⇒ Object
Returns the value of an attribute specified by its name.
- #obj_class ⇒ Scrivito::ObjClass? deprecated Deprecated.
-
#obj_class_name ⇒ String
Returns the obj class name of this object.
-
#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.
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
.
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_class ⇒ Scrivito::ObjClass?
Returns the obj class of this object.
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_name ⇒ String
Returns the obj class name of this object.
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.
108 109 |
# File 'lib/scrivito/attribute_content.rb', line 108 def (field_name) end |