Class: Contentful::Management::Entry
- Inherits:
-
Object
- Object
- Contentful::Management::Entry
- 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.
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::Metadata
Attributes included from Resource
#client, #properties, #raw_object, #request
Class Method Summary collapse
-
.fields_with_locale(content_type, attributes) ⇒ Hash
Gets Hash of fields for all locales, with locales at a field level.
Instance Method Summary collapse
-
#locale ⇒ String
Returns the currently supported local.
-
#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::EnvironmentAware
Methods included from Resource::Refresher
Methods included from Resource::Publisher
#publish, #published?, #unpublish, #updated?
Methods included from Resource::Archiver
#archive, #archived?, #unarchive
Methods included from Resource::Fields
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_type ⇒ Object
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
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
#locale ⇒ String
Returns the currently supported local.
140 141 142 |
# File 'lib/contentful/management/entry.rb', line 140 def locale sys[:locale] || default_locale 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.
179 180 181 |
# File 'lib/contentful/management/entry.rb', line 179 def snapshots EntrySnapshotMethodsFactory.new(self) end |