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
Defined Under Namespace
Modules: ArrayLike, AssetFields, CustomResource, Fields, SystemProperties
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
rubocop:enable Style/DoubleNegation.
-
#default_locale ⇒ Object
readonly
rubocop:enable Style/DoubleNegation.
-
#properties ⇒ Object
readonly
rubocop:enable Style/DoubleNegation.
-
#raw ⇒ Object
readonly
rubocop:enable Style/DoubleNegation.
-
#request ⇒ Object
readonly
rubocop:enable Style/DoubleNegation.
Instance Method Summary collapse
-
#array? ⇒ Boolean
Returns true for resources that behave like an array.
-
#fields ⇒ Object
Resources that don’t include Fields or AssetFields return nil for #fields.
-
#localized?(value) ⇒ Boolean
Returns true if resource is localized.
-
#reload ⇒ Object
Issues the request that was made to fetch this response again.
-
#sys ⇒ Object
Resources that don’t include SystemProperties return nil for #sys.
Instance Attribute Details
#client ⇒ Object (readonly)
rubocop:enable Style/DoubleNegation
29 30 31 |
# File 'lib/contentful/resource.rb', line 29 def client @client end |
#default_locale ⇒ Object (readonly)
rubocop:enable Style/DoubleNegation
29 30 31 |
# File 'lib/contentful/resource.rb', line 29 def default_locale @default_locale end |
#properties ⇒ Object (readonly)
rubocop:enable Style/DoubleNegation
29 30 31 |
# File 'lib/contentful/resource.rb', line 29 def properties @properties end |
#raw ⇒ Object (readonly)
rubocop:enable Style/DoubleNegation
29 30 31 |
# File 'lib/contentful/resource.rb', line 29 def raw @raw end |
#request ⇒ Object (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
60 61 62 |
# File 'lib/contentful/resource.rb', line 60 def array? false end |
#fields ⇒ Object
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
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 |
#reload ⇒ Object
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 |
#sys ⇒ Object
Resources that don’t include SystemProperties return nil for #sys
73 74 75 |
# File 'lib/contentful/resource.rb', line 73 def sys nil end |