Class: Scrivito::ObjClass Deprecated
- Inherits:
-
Object
- Object
- Scrivito::ObjClass
- Defined in:
- lib/scrivito/obj_class.rb
Overview
This class represents a CMS obj class. Obj classes can be created, updated and all properties can be read. The class also provides methods to find obj classes. The attributes of an obj class are defined by Attribute instances.
Instance Attribute Summary collapse
- #attributes ⇒ Scrivito::AttributeCollection readonly deprecated Deprecated.
- #id ⇒ String readonly deprecated Deprecated.
- #is_active ⇒ Boolean (also: #active?) readonly deprecated Deprecated.
- #name ⇒ String readonly deprecated Deprecated.
Class Method Summary collapse
- .all ⇒ Object deprecated Deprecated.
- .create(properties) ⇒ Scrivito::ObjClass deprecated Deprecated.
- .find(name) ⇒ Scrivito::ObjClass deprecated Deprecated.
-
.remove ⇒ Object
Remove all obj classes.
Instance Method Summary collapse
- #is_binary ⇒ Boolean (also: #binary?) deprecated Deprecated.
- #legacy_type? ⇒ Boolean deprecated Deprecated.
- #update(properties) ⇒ nil deprecated Deprecated.
Instance Attribute Details
#attributes ⇒ Scrivito::AttributeCollection (readonly)
Returns the attributes of this obj class.
203 204 205 |
# File 'lib/scrivito/obj_class.rb', line 203 def attributes @attributes end |
#id ⇒ String (readonly)
Returns unique identifier of this obj class.
166 |
# File 'lib/scrivito/obj_class.rb', line 166 delegate :id, :name, :is_active, to: :obj_class_data |
#is_active ⇒ Boolean (readonly) Also known as: active?
Returns whether instances can be created with this obj class.
166 |
# File 'lib/scrivito/obj_class.rb', line 166 delegate :id, :name, :is_active, to: :obj_class_data |
#name ⇒ String (readonly)
Returns the name of this obj class.
166 |
# File 'lib/scrivito/obj_class.rb', line 166 delegate :id, :name, :is_active, to: :obj_class_data |
Class Method Details
.all ⇒ Object
Returns all obj classes.
39 40 41 |
# File 'lib/scrivito/obj_class.rb', line 39 def all Workspace.current.obj_classes end |
.create(properties) ⇒ Scrivito::ObjClass
the is_binary
option is deprecated
Creates a new obj class and persists it in the CMS.
This allows you to set the different properties of an obj class by providing a hash with the property names as keys and the values you want to set as values. Attributes can be either given as Attribute instances or as an attribute property hash.
107 108 109 |
# File 'lib/scrivito/obj_class.rb', line 107 def create(properties) Scrivito.raise_obj_class_deprecated_error end |
.find(name) ⇒ Scrivito::ObjClass
Finds an obj class by its name.
54 55 56 57 58 59 60 61 62 |
# File 'lib/scrivito/obj_class.rb', line 54 def find(name) obj_class = Workspace.current.obj_classes[name] unless obj_class raise ResourceNotFound, "Could not find '#{ObjClass}' with name '#{name}'." end obj_class end |
.remove ⇒ Object
Remove all obj classes.
This method removes all classes in the corresponding workspace. By doing that it migrates the contents of the workspace. The migrated workspace will not use Scrivito::ObjClass, Attribute etc. anymore to determine which attributes an Obj has, but will use attributes defined in model with AttributeContent::ClassMethods#attribute. The id
of the current workspace must be “rtc”. For detailed migration instructions please visit scrivito.com/obj-class-migration.
26 27 28 29 30 31 32 |
# File 'lib/scrivito/obj_class.rb', line 26 def remove if Workspace.current.rtc? Workspace.current.api_request(:delete, '/obj_classes') else raise ScrivitoError, 'Scrivito::ObjClass.remove is only allowed in the "rtc" workspace.' end end |
Instance Method Details
#is_binary ⇒ Boolean Also known as: binary?
Returns whether instances of this class are binary, e.g. images or PDFs.
173 174 175 176 177 178 179 180 |
# File 'lib/scrivito/obj_class.rb', line 173 def is_binary if legacy_type? obj_class_data.is_binary else raise ScrivitoError, %(`is_binary' and `binary?' can only be called on ObjClasses with a legacy_type.) end end |
#legacy_type? ⇒ Boolean
Returns true if this ObjClass was created with a is_binary
option. Creating ObjClass with this option is deprecated and will be removed.
150 151 152 |
# File 'lib/scrivito/obj_class.rb', line 150 def legacy_type? !!obj_class_data.type end |
#update(properties) ⇒ nil
Updates this obj class and persists the changes in the CMS. It is not possible to update the name
.
See create for a detailed overview of what properties are allowed and how to set them.
The is_binary
option can only be removed. By passing nil
for the is_binary
option to update, you can convert legacy objects. This conversion removes the fields title
, body
(if is_binary
was false
) or blob
(if is_binary
was true
). If you add the fields in the same request the values will be kept for all objs.
236 237 238 |
# File 'lib/scrivito/obj_class.rb', line 236 def update(properties) Scrivito.raise_obj_class_deprecated_error end |