Class: Contentful::Management::ContentType
- Inherits:
-
Object
- Object
- Contentful::Management::ContentType
- Extended by:
- Resource::AllPublished
- Includes:
- Resource, Resource::EnvironmentAware, Resource::Publisher, Resource::Refresher, Resource::SystemProperties
- Defined in:
- lib/contentful/management/content_type.rb
Overview
Resource class for ContentType.
Constant Summary collapse
- FIELD_TYPES =
Shortcuts for Contentful Field Types
[ SYMBOL = 'Symbol'.freeze, TEXT = 'Text'.freeze, INTEGER = 'Integer'.freeze, FLOAT = 'Number'.freeze, DATE = 'Date'.freeze, BOOLEAN = 'Boolean'.freeze, LINK = 'Link'.freeze, ARRAY = 'Array'.freeze, OBJECT = 'Object'.freeze, LOCATION = 'Location'.freeze, STRUCTURED_TEXT = 'StructuredText'.freeze ].freeze
Instance Attribute Summary
Attributes included from Resource::SystemProperties
Attributes included from Resource
#client, #default_locale, #properties, #raw_object, #request
Instance Method Summary collapse
-
#fields ⇒ Contentful::Management::ContentType
Use this method only in the context of content type.
-
#save ⇒ Contentful::Management::ContentType
If a content type is a new object gets created in the Contentful, otherwise the existing entry gets updated.
-
#snapshots ⇒ Contentful::Management::ContentTypeSnapshotMethodsFactory
Allows manipulation of snapshots in context of the current content type Allows listing all snapshots belonging to this entry and finding one by id.
Methods included from Resource::AllPublished
Methods included from Resource::EnvironmentAware
Methods included from Resource::Publisher
#publish, #published?, #unpublish
Methods included from Resource::Refresher
Methods included from Resource
#array?, #destroy, #environment_id, #nested_locale_fields?, #resource?, #sys, #update
Instance Method Details
#fields ⇒ Contentful::Management::ContentType
Use this method only in the context of content type. Allows you to add and create a field with specified attributes or destroy by pass field id.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/contentful/management/content_type.rb', line 111 def fields fields = orig_fields fields.instance_exec(self) do |content_type| fields.define_singleton_method(:add) do |field| content_type.update(fields: content_type.merged_fields(field)) end fields.define_singleton_method(:create) do |params| field = Contentful::Management::Field.new Field.property_coercions.each do |key, _value| snakify_key = Support.snakify(key) param = params[snakify_key.to_sym] field.send("#{snakify_key}=", param) if param end content_type.update(fields: content_type.merged_fields(field)) end fields.define_singleton_method(:destroy) do |id| fields = content_type.fields.reject { |field| field.id == id } content_type.update(fields: fields) end end fields end |
#save ⇒ Contentful::Management::ContentType
If a content type is a new object gets created in the Contentful, otherwise the existing entry gets updated.
81 82 83 84 85 86 87 88 |
# File 'lib/contentful/management/content_type.rb', line 81 def save if id update(@properties) else new_instance = self.class.create(client, space.id, environment_id, @properties) refresh_data(new_instance) end end |
#snapshots ⇒ Contentful::Management::ContentTypeSnapshotMethodsFactory
Allows manipulation of snapshots in context of the current content type Allows listing all snapshots belonging to this entry and finding one by id.
165 166 167 |
# File 'lib/contentful/management/content_type.rb', line 165 def snapshots ContentTypeSnapshotMethodsFactory.new(self) end |