Class: JSONAPI::Serializable::Resource::Relationship
- Inherits:
-
Object
- Object
- JSONAPI::Serializable::Resource::Relationship
- Includes:
- DSL
- Defined in:
- lib/jsonapi/serializable/resource/relationship.rb,
lib/jsonapi/serializable/resource/relationship/dsl.rb
Defined Under Namespace
Modules: DSL
Instance Method Summary collapse
- #as_jsonapi(included) ⇒ Object
-
#initialize(exposures = {}, options = {}, &block) ⇒ Relationship
constructor
A new instance of Relationship.
- #links ⇒ Object private
- #meta ⇒ Object private
- #related_resources ⇒ Object private
- #resources ⇒ Object private
Methods included from DSL
Constructor Details
#initialize(exposures = {}, options = {}, &block) ⇒ Relationship
Returns a new instance of Relationship.
10 11 12 13 14 15 16 |
# File 'lib/jsonapi/serializable/resource/relationship.rb', line 10 def initialize(exposures = {}, = {}, &block) exposures.each { |k, v| instance_variable_set("@#{k}", v) } @_exposures = exposures @_options = @_links = {} instance_eval(&block) end |
Instance Method Details
#as_jsonapi(included) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/jsonapi/serializable/resource/relationship.rb', line 18 def as_jsonapi(included) {}.tap do |hash| hash[:links] = @_links if @_links.any? hash[:data] = linkage_data if included || @_include_linkage hash[:meta] = @_meta unless @_meta.nil? hash[:meta] = { included: false } if hash.empty? end end |
#links ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 |
# File 'lib/jsonapi/serializable/resource/relationship.rb', line 33 def links @_links end |
#meta ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 |
# File 'lib/jsonapi/serializable/resource/relationship.rb', line 38 def @_meta end |
#related_resources ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/jsonapi/serializable/resource/relationship.rb', line 28 def @_related_resources ||= Array(resources) end |
#resources ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 |
# File 'lib/jsonapi/serializable/resource/relationship.rb', line 43 def resources @_resources ||= @_resources_block.call end |