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.
- #references(query = {}, headers = {}) ⇒ Object
-
#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
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_type ⇒ Object
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
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
#locale ⇒ String
Returns the currently supported local.
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 |
#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.
180 181 182 |
# File 'lib/contentful/management/entry.rb', line 180 def snapshots EntrySnapshotMethodsFactory.new(self) end |