Module: Contentful::Resource
- Defined in:
- lib/contentful/resource.rb,
lib/contentful/resource/fields.rb,
lib/contentful/resource/asset_fields.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: AssetFields, ClassMethods, Fields, SystemProperties
Constant Summary collapse
- COERCIONS =
{ string: ->(v) { v.to_s }, integer: ->(v) { v.to_i }, float: ->(v) { v.to_f }, boolean: ->(v) { !!v }, date: ->(v) { DateTime.parse(v) } }
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
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.
- #initialize(object, request = nil, client = nil) ⇒ Object
- #inspect(info = nil) ⇒ Object
-
#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)
Returns the value of attribute client.
22 23 24 |
# File 'lib/contentful/resource.rb', line 22 def client @client end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
22 23 24 |
# File 'lib/contentful/resource.rb', line 22 def properties @properties end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
22 23 24 |
# File 'lib/contentful/resource.rb', line 22 def request @request end |
Instance Method Details
#array? ⇒ Boolean
Returns true for resources that behave like an array
38 39 40 |
# File 'lib/contentful/resource.rb', line 38 def array? false end |
#fields ⇒ Object
Resources that don’t include Fields or AssetFields return nil for #fields
48 49 50 |
# File 'lib/contentful/resource.rb', line 48 def fields nil end |
#initialize(object, request = nil, client = nil) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/contentful/resource.rb', line 24 def initialize(object, request = nil, client = nil) self.class.update_coercions! @properties = extract_from_object object, :property, self.class.property_coercions.keys @request = request @client = client end |
#inspect(info = nil) ⇒ Object
32 33 34 35 |
# File 'lib/contentful/resource.rb', line 32 def inspect(info = nil) properties_info = properties.empty? ? '' : " @properties=#{properties.inspect}" "#<#{self.class}:#{properties_info}#{info}>" end |
#reload ⇒ Object
Issues the request that was made to fetch this response again. Only works for top-level resources
54 55 56 57 58 59 60 |
# File 'lib/contentful/resource.rb', line 54 def reload if request request.get else false end end |
#sys ⇒ Object
Resources that don’t include SystemProperties return nil for #sys
43 44 45 |
# File 'lib/contentful/resource.rb', line 43 def sys nil end |