Class: Contentful::Management::Entry

Inherits:
Object
  • Object
show all
Extended by:
Resource::AllPublished, Resource::EntryFields
Includes:
Resource, Resource::Archiver, Resource::Fields, 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

#client, #default_locale, #properties, #raw_object, #request

Instance Method Summary collapse

Methods included from Resource::EntryFields

fields_coercions

Methods included from Resource::AllPublished

all_published

Methods included from Resource::Publisher

#publish, #published?, #unpublish

Methods included from Resource::Archiver

#archive, #archived?, #unarchive

Methods included from Resource::Fields

included

Methods included from Resource::Refresher

#reload

Methods included from Resource

#array?, #destroy, #nested_locale_fields?, #resource?, #sys, #update

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



188
189
190
191
192
193
194
195
196
197
198
# File 'lib/contentful/management/entry.rb', line 188

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.



26
27
28
# File 'lib/contentful/management/entry.rb', line 26

def content_type
  @content_type
end

Instance Method Details

#fields(wanted_locale = locale) ⇒ Hash

Gets Hash of fields for the current locale

Parameters:

  • wanted_locale (String) (defaults to: locale)

Returns:

  • (Hash)

    localized fields



80
81
82
83
84
85
86
# File 'lib/contentful/management/entry.rb', line 80

def fields(wanted_locale = locale)
  requested_locale = wanted_locale || default_locale
  @fields[requested_locale] = {} unless @fields[requested_locale]

  default_fields = @fields[default_locale] || {}
  default_fields.merge(@fields[requested_locale])
end

#localeString

Returns the currently supported local.

Returns:

  • (String)

    current_locale



109
110
111
# File 'lib/contentful/management/entry.rb', line 109

def locale
  sys[:locale] || default_locale
end

#saveContentful::Management::Entry

If an entry is a new object gets created in the Contentful, otherwise the existing entry gets updated.

Returns:

See Also:

  • README for details.


92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/contentful/management/entry.rb', line 92

def save
  if id
    update({})
  else
    new_instance = Contentful::Management::Entry.create(
      client,
      content_type.space.id,
      content_type: content_type,
      fields: instance_variable_get(:@fields)
    )
    refresh_data(new_instance)
  end
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.


148
149
150
# File 'lib/contentful/management/entry.rb', line 148

def snapshots
  EntrySnapshotMethodsFactory.new(self)
end