Class: Contentful::Management::Entry

Inherits:
Object
  • Object
show all
Extended by:
Resource::EntryFields
Includes:
Resource, Resource::Archiver, Resource::EnvironmentAware, Resource::Fields, Resource::Metadata, Resource::Publisher, Resource::Refresher, Resource::SystemProperties
Defined in:
lib/contentful/management/entry.rb

Overview

Resource class for Entry.

See Also:

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

Direct Known Subclasses

DynamicEntry

Instance Attribute Summary collapse

Attributes included from Resource::SystemProperties

#sys

Attributes included from Resource::Metadata

#_metadata

Attributes included from Resource

#client, #properties, #raw_object, #request

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource::EntryFields

fields_coercions

Methods included from Resource::EnvironmentAware

#environment_id

Methods included from Resource::Refresher

#reload

Methods included from Resource::Publisher

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

Methods included from Resource::Archiver

#archive, #archived?, #unarchive

Methods included from Resource::Fields

#fields, included

Methods included from Resource

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)

rubocop:disable Style/MethodMissing



222
223
224
225
226
227
228
229
230
231
232
# File 'lib/contentful/management/entry.rb', line 222

def method_missing(name, *args, &block)
  if content_type.nil?
    fetch_content_type

    Contentful::Management::Resource::FieldAware.create_fields_for_content_type(self)

    return send(name, *args, &block) if respond_to? name
  end

  fail NameError.new("undefined local variable or method `#{name}' for #{self.class}:#{sys[:id]}", name)
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



31
32
33
# File 'lib/contentful/management/entry.rb', line 31

def content_type
  @content_type
end

Class Method Details

.fields_with_locale(content_type, attributes) ⇒ Hash

Gets Hash of fields for all locales, with locales at a field level

Returns:

  • (Hash)

    fields by locale



121
122
123
124
125
126
127
128
129
130
131
# File 'lib/contentful/management/entry.rb', line 121

def self.fields_with_locale(content_type, attributes)
  locale = attributes[:locale] || content_type.sys[:space].default_locale
  fields = content_type.properties[:fields]
  field_names = fields.map { |field| field.id.to_sym }
  attributes = attributes.keep_if { |key| field_names.include?(key) }

  attributes.each_with_object({}) do |(id, value), result|
    field = fields.detect { |f| f.id.to_sym == id.to_sym }
    result[id] = { locale => parse_attribute_with_field(value, field) }
  end
end

Instance Method Details

#localeString

Returns the currently supported local.

Returns:

  • (String)

    current_locale



141
142
143
# File 'lib/contentful/management/entry.rb', line 141

def locale
  sys[:locale] || default_locale
end

#references(query = {}, headers = {}) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/contentful/management/entry.rb', line 184

def references(query = {}, headers = {})
  ResourceRequester.new(client, self.class).all(
    {
      space_id: space.id,
      environment_id: environment_id,
      resource_id: id,
      suffix: '/references'
    },
    query,
    headers
  )
end

#snapshotsContentful::Management::EntrySnapshotMethodsFactory

Allows manipulation of snapshots in context of the current entry Allows listing all snapshots belonging to this entry and finding one by id.

Returns:

  • (Contentful::Management::EntrySnapshotMethodsFactory)

See Also:

  • README for details.


180
181
182
# File 'lib/contentful/management/entry.rb', line 180

def snapshots
  EntrySnapshotMethodsFactory.new(self)
end