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



207
208
209
210
211
212
213
214
215
216
217
# File 'lib/contentful/management/entry.rb', line 207

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.



29
30
31
# File 'lib/contentful/management/entry.rb', line 29

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



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

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



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

def locale
  sys[:locale] || default_locale
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.


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

def snapshots
  EntrySnapshotMethodsFactory.new(self)
end