Class: Contentful::Management::ContentType

Inherits:
Object
  • Object
show all
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.

See Also:

  • https://www.contentful.com/developers/documentation/content-management-api/#resources-content-types

Constant Summary collapse

FIELD_TYPES =

Shortcuts for Contentful Field Types

[
  SYMBOL = 'Symbol',
  TEXT = 'Text',
  INTEGER = 'Integer',
  FLOAT = 'Number',
  DATE = 'Date',
  BOOLEAN = 'Boolean',
  LINK = 'Link',
  ARRAY = 'Array',
  OBJECT = 'Object',
  LOCATION = 'Location',
  STRUCTURED_TEXT = 'RichText'
].freeze

Instance Attribute Summary

Attributes included from Resource::SystemProperties

#sys

Attributes included from Resource

#client, #properties, #raw_object, #request

Instance Method Summary collapse

Methods included from Resource::AllPublished

all_published

Methods included from Resource::EnvironmentAware

#environment_id

Methods included from Resource::Publisher

#publish, #published?, #unpublish, #updated?

Methods included from Resource::Refresher

#reload

Methods included from Resource

#array?, #default_locale, #destroy, #environment_id, #nested_locale_fields?, #resource?, #save, #sys, #update

Instance Method Details

#fieldsContentful::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.

Returns:

See Also:

  • README for details.


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/contentful/management/content_type.rb', line 100

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

#snapshotsContentful::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.

Returns:

  • (Contentful::Management::ContentTypeSnapshotMethodsFactory)

See Also:

  • README for details.


154
155
156
# File 'lib/contentful/management/content_type.rb', line 154

def snapshots
  ContentTypeSnapshotMethodsFactory.new(self)
end