Module: Contentful::Resource

Included in:
Array, Asset, ContentType, DeletedAsset, DeletedEntry, Entry, Field, File, Link, Locale, Location, Space, SyncPage
Defined in:
lib/contentful/resource.rb,
lib/contentful/resource/fields.rb,
lib/contentful/resource/array_like.rb,
lib/contentful/resource/asset_fields.rb,
lib/contentful/resource/custom_resource.rb,
lib/contentful/resource/system_properties.rb

Overview

Include this module to declare a class to be a contentful resource. This is done by the default in the existing resource classes

You can define your own classes that behave like contentful resources: See examples/custom_classes.rb to see how.

Take a look at examples/resource_mapping.rb on how to register them to be returned by the client by default

See Also:

  • examples/custom_classes.rb Custom Class as Resource
  • examples/resource_mapping.rb Mapping a Custom Class

Defined Under Namespace

Modules: ArrayLike, AssetFields, CustomResource, Fields, SystemProperties

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject (readonly)

rubocop:enable Style/DoubleNegation



29
30
31
# File 'lib/contentful/resource.rb', line 29

def client
  @client
end

#default_localeObject (readonly)

rubocop:enable Style/DoubleNegation



29
30
31
# File 'lib/contentful/resource.rb', line 29

def default_locale
  @default_locale
end

#propertiesObject (readonly)

rubocop:enable Style/DoubleNegation



29
30
31
# File 'lib/contentful/resource.rb', line 29

def properties
  @properties
end

#rawObject (readonly)

rubocop:enable Style/DoubleNegation



29
30
31
# File 'lib/contentful/resource.rb', line 29

def raw
  @raw
end

#requestObject (readonly)

rubocop:enable Style/DoubleNegation



29
30
31
# File 'lib/contentful/resource.rb', line 29

def request
  @request
end

Instance Method Details

#array?Boolean

Returns true for resources that behave like an array

Returns:

  • (Boolean)


60
61
62
# File 'lib/contentful/resource.rb', line 60

def array?
  false
end

#fieldsObject

Resources that don’t include Fields or AssetFields return nil for #fields



78
79
80
# File 'lib/contentful/resource.rb', line 78

def fields
  nil
end

#localized?(value) ⇒ Boolean

Returns true if resource is localized

Returns:

  • (Boolean)


67
68
69
70
# File 'lib/contentful/resource.rb', line 67

def localized?(value)
  return false unless value.is_a? ::Hash
  value.keys.any? { |possible_locale| Contentful::Constants::KNOWN_LOCALES.include?(possible_locale) }
end

#reloadObject

Issues the request that was made to fetch this response again. Only works for top-level resources



84
85
86
87
88
89
90
# File 'lib/contentful/resource.rb', line 84

def reload
  if request
    request.get
  else
    false
  end
end

#sysObject

Resources that don’t include SystemProperties return nil for #sys



73
74
75
# File 'lib/contentful/resource.rb', line 73

def sys
  nil
end