Class: FulfilApi::Resource
- Inherits:
-
Object
- Object
- FulfilApi::Resource
- Includes:
- AttributeAssignable
- Defined in:
- lib/fulfil_api/resource.rb,
lib/fulfil_api/resource/relation.rb,
lib/fulfil_api/resource/attribute_type.rb,
lib/fulfil_api/resource/relation/naming.rb,
lib/fulfil_api/resource/relation/loadable.rb,
lib/fulfil_api/resource/attribute_assignable.rb,
lib/fulfil_api/resource/relation/query_methods.rb
Overview
The Resource represents a single resource returned by the API
endpoints of Fulfil.
Defined Under Namespace
Modules: AttributeAssignable Classes: AttributeType, Relation
Class Method Summary collapse
-
.relation ⇒ FulfilApi::Resource::Relation
Builds a new Fulfil::Resource::Relation based on the current class to enable us to chain requests to Fulfil without querying their API endpoints multiple times in a row.
Instance Method Summary collapse
-
#[](attribute_name) ⇒ Any?
Looks up the value for the given attribute name.
-
#initialize(attributes = {}) ⇒ Resource
constructor
A new instance of Resource.
-
#to_h ⇒ Hash
Returns all currently assigned attributes for a Resource.
Methods included from AttributeAssignable
#assign_attribute, #assign_attributes
Constructor Details
#initialize(attributes = {}) ⇒ Resource
Returns a new instance of Resource.
9 10 11 12 |
# File 'lib/fulfil_api/resource.rb', line 9 def initialize(attributes = {}) @attributes = {}.with_indifferent_access assign_attributes(attributes) end |
Class Method Details
.relation ⇒ FulfilApi::Resource::Relation
it makes use of the delegate_missing_to method from ActiveSupport to ensure that all unknown class methods for the FulfilApi::Resource are forwarded to the relation.
Builds a new Fulfil::Resource::Relation based on the current class to
enable us to chain requests to Fulfil without querying their API endpoints
multiple times in a row.
29 30 31 |
# File 'lib/fulfil_api/resource.rb', line 29 def relation Relation.new(self) end |
Instance Method Details
#[](attribute_name) ⇒ Any?
Looks up the value for the given attribute name.
38 39 40 |
# File 'lib/fulfil_api/resource.rb', line 38 def [](attribute_name) @attributes[attribute_name] end |
#to_h ⇒ Hash
Returns all currently assigned attributes for a FulfilApi::Resource.
45 46 47 |
# File 'lib/fulfil_api/resource.rb', line 45 def to_h @attributes end |