Class: JsonApi::Resource
- Inherits:
-
Object
- Object
- JsonApi::Resource
- Extended by:
- JsonApi::Resources::DSL
- Includes:
- JsonApi::Resources::Base
- Defined in:
- lib/json_api_ruby/resource.rb
Instance Attribute Summary collapse
-
#_model ⇒ Object
The model that is used to fill out the data and attributes objects.
-
#includes ⇒ Object
readonly
Includes can be passed in from a request See: jsonapi.org/format/#fetching-includes.
Attributes included from JsonApi::Resources::DSL
#_id_field, #_type, #_use_links, #fields, #relationships
Attributes included from JsonApi::Resources::Base
Class Method Summary collapse
Instance Method Summary collapse
-
#id ⇒ Object
Can be set using ‘id_field` in the created resource class like so:.
-
#initialize(model, options = {}) ⇒ Resource
constructor
A new instance of Resource.
-
#object ⇒ Object
Makes the underlying object available to subclasses so we can do things like.
-
#type ⇒ Object
Can be overridden in a subclass.
- #use_links ⇒ Object
Methods included from JsonApi::Resources::DSL
attribute, attributes, has_many, has_one, id_field
Methods included from JsonApi::Resources::Base
#attributes_hash, #build_object_graph, #fields_array, #identifier_hash, #links_hash, #relationships_array, #self_link_path, #to_hash
Constructor Details
Instance Attribute Details
#_model ⇒ Object
The model that is used to fill out the data and attributes objects
54 55 56 |
# File 'lib/json_api_ruby/resource.rb', line 54 def _model @_model end |
#includes ⇒ Object (readonly)
Includes can be passed in from a request See:
http://jsonapi.org/format/#fetching-includes
59 60 61 |
# File 'lib/json_api_ruby/resource.rb', line 59 def includes @includes end |
Class Method Details
.inherited(subclass) ⇒ Object
9 10 11 12 |
# File 'lib/json_api_ruby/resource.rb', line 9 def self.inherited(subclass) subclass.id_field(@_id_field || :id) subclass.use_links(@_use_links || JsonApi.configuration.use_links) end |
Instance Method Details
#id ⇒ Object
21 22 23 |
# File 'lib/json_api_ruby/resource.rb', line 21 def id object.public_send(self.class._id_field).to_s end |
#object ⇒ Object
49 50 51 |
# File 'lib/json_api_ruby/resource.rb', line 49 def object _model end |
#type ⇒ Object
Can be overridden in a subclass
26 27 28 29 30 31 32 |
# File 'lib/json_api_ruby/resource.rb', line 26 def type if self.class._type self.class._type else @type ||= _model.class.to_s.underscore.pluralize end end |
#use_links ⇒ Object
34 35 36 |
# File 'lib/json_api_ruby/resource.rb', line 34 def use_links self.class._use_links end |