Class: Contentful::BaseResource
- Inherits:
-
Object
- Object
- Contentful::BaseResource
- Defined in:
- lib/contentful/base_resource.rb
Overview
Base definition of a Contentful Resource containing Sys properties
Direct Known Subclasses
Array, ContentType, DeletedAsset, DeletedEntry, FieldsResource, Link, Locale, Space, SyncPage
Instance Attribute Summary collapse
-
#_metadata ⇒ Object
readonly
Returns the value of attribute _metadata.
-
#default_locale ⇒ Object
readonly
Returns the value of attribute default_locale.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#sys ⇒ Object
readonly
Returns the value of attribute sys.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Definition of equality.
-
#initialize(item, configuration = {}, _localized = false, _includes = Includes.new, entries = {}, depth = 0, _errors = []) ⇒ BaseResource
constructor
rubocop:disable Metrics/ParameterLists.
- #inspect ⇒ Object
- #marshal_dump ⇒ Object
- #marshal_load(raw_object) ⇒ Object
-
#reload(client = nil) ⇒ Object
Issues the request that was made to fetch this response again.
Constructor Details
#initialize(item, configuration = {}, _localized = false, _includes = Includes.new, entries = {}, depth = 0, _errors = []) ⇒ BaseResource
rubocop:disable Metrics/ParameterLists
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/contentful/base_resource.rb', line 11 def initialize(item, configuration = {}, _localized = false, _includes = Includes.new, entries = {}, depth = 0, _errors = []) entries["#{item['sys']['type']}:#{item['sys']['id']}"] = self if entries && item.key?('sys') @raw = item @default_locale = configuration[:default_locale] @depth = depth @configuration = configuration @sys = hydrate_sys @_metadata = define_sys_methods! end |
Instance Attribute Details
#_metadata ⇒ Object (readonly)
Returns the value of attribute _metadata.
8 9 10 |
# File 'lib/contentful/base_resource.rb', line 8 def @_metadata end |
#default_locale ⇒ Object (readonly)
Returns the value of attribute default_locale.
8 9 10 |
# File 'lib/contentful/base_resource.rb', line 8 def default_locale @default_locale end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
8 9 10 |
# File 'lib/contentful/base_resource.rb', line 8 def raw @raw end |
#sys ⇒ Object (readonly)
Returns the value of attribute sys.
8 9 10 |
# File 'lib/contentful/base_resource.rb', line 8 def sys @sys end |
Instance Method Details
#==(other) ⇒ Object
Definition of equality
29 30 31 |
# File 'lib/contentful/base_resource.rb', line 29 def ==(other) self.class == other.class && sys[:id] == other.sys[:id] end |
#inspect ⇒ Object
24 25 26 |
# File 'lib/contentful/base_resource.rb', line 24 def inspect "<#{repr_name} id='#{sys[:id]}'>" end |
#marshal_dump ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/contentful/base_resource.rb', line 34 def marshal_dump entry_mapping = @configuration[:entry_mapping].each_with_object({}) do |(k, v), res| res[k] = v.to_s end { # loggers usually have a file handle that can't be marshalled, so let's not return that configuration: @configuration.merge(entry_mapping: entry_mapping, logger: nil), raw: raw } end |
#marshal_load(raw_object) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/contentful/base_resource.rb', line 47 def marshal_load(raw_object) raw_object[:configuration][:entry_mapping] = raw_object[:configuration].fetch(:entry_mapping, {}).each_with_object({}) do |(k, v), res| begin v = v.to_s unless v.is_a?(::String) res[k] = v.split('::').inject(Object) { |o, c| o.const_get c } rescue next end end @raw = raw_object[:raw] @configuration = raw_object[:configuration] @default_locale = @configuration[:default_locale] @sys = hydrate_sys @_metadata = @depth = 0 define_sys_methods! end |
#reload(client = nil) ⇒ Object
Issues the request that was made to fetch this response again. Only works for Entry, Asset, ContentType and Space
68 69 70 71 72 |
# File 'lib/contentful/base_resource.rb', line 68 def reload(client = nil) return client.send(Support.snakify(self.class.name.split('::').last), id) unless client.nil? false end |