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