Class: Contentful::Management::Entry
- Inherits:
-
Object
- Object
- Contentful::Management::Entry
- 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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#content_type ⇒ Object
Returns the value of attribute content_type.
Attributes included from Resource::SystemProperties
Attributes included from Resource
#client, #default_locale, #properties, #raw_object, #request
Instance Method Summary collapse
-
#fields(wanted_locale = locale) ⇒ Hash
Gets Hash of fields for the current locale.
-
#locale ⇒ String
Returns the currently supported local.
-
#save ⇒ Contentful::Management::Entry
If an entry is a new object gets created in the Contentful, otherwise the existing entry gets updated.
-
#snapshots ⇒ Contentful::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.
Methods included from Resource::EntryFields
Methods included from Resource::AllPublished
Methods included from Resource::Publisher
#publish, #published?, #unpublish
Methods included from Resource::Archiver
#archive, #archived?, #unarchive
Methods included from Resource::Fields
Methods included from Resource::Refresher
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_type ⇒ Object
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
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 |
#locale ⇒ String
Returns the currently supported local.
109 110 111 |
# File 'lib/contentful/management/entry.rb', line 109 def locale sys[:locale] || default_locale end |
#save ⇒ Contentful::Management::Entry
If an entry is a new object gets created in the Contentful, otherwise the existing entry gets updated.
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 |
#snapshots ⇒ Contentful::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.
148 149 150 |
# File 'lib/contentful/management/entry.rb', line 148 def snapshots EntrySnapshotMethodsFactory.new(self) end |