Class: Contentful::BaseResource

Inherits:
Object
  • Object
show all
Defined in:
lib/contentful/base_resource.rb

Overview

Base definition of a Contentful Resource containing Sys properties

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item, configuration = {}, _localized = false, _includes = [], entries = {}, depth = 0, _errors = []) ⇒ BaseResource

rubocop:disable Metrics/ParameterLists



9
10
11
12
13
14
15
16
17
18
# File 'lib/contentful/base_resource.rb', line 9

def initialize(item, configuration = {}, _localized = false, _includes = [], 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

  define_sys_methods!
end

Instance Attribute Details

#default_localeObject (readonly)

Returns the value of attribute default_locale



6
7
8
# File 'lib/contentful/base_resource.rb', line 6

def default_locale
  @default_locale
end

#rawObject (readonly)

Returns the value of attribute raw



6
7
8
# File 'lib/contentful/base_resource.rb', line 6

def raw
  @raw
end

#sysObject (readonly)

Returns the value of attribute sys



6
7
8
# File 'lib/contentful/base_resource.rb', line 6

def sys
  @sys
end

Instance Method Details

#==(other) ⇒ Object

Definition of equality



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

def ==(other)
  self.class == other.class && sys[:id] == other.sys[:id]
end

#reload(client = nil) ⇒ Object

Issues the request that was made to fetch this response again. Only works for Entry, Asset, ContentType and Space



50
51
52
53
54
# File 'lib/contentful/base_resource.rb', line 50

def reload(client = nil)
  return client.send(Support.snakify(self.class.name.split('::').last), id) unless client.nil?

  false
end