Class: JSONAPI::Serializable::Relationship
- Inherits:
-
Object
- Object
- JSONAPI::Serializable::Relationship
- Includes:
- DSL
- Defined in:
- lib/jsonapi/serializable/relationship.rb,
lib/jsonapi/serializable/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.
- #related_resources ⇒ Object private
Methods included from DSL
Constructor Details
#initialize(exposures = {}, options = {}, &block) ⇒ Relationship
Returns a new instance of Relationship.
9 10 11 12 13 14 15 |
# File 'lib/jsonapi/serializable/relationship.rb', line 9 def initialize(exposures = {}, = {}, &block) exposures.each { |k, v| instance_variable_set("@#{k}", v) } @_exposures = exposures = @_links = {} instance_eval(&block) end |
Instance Method Details
#as_jsonapi(included) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/jsonapi/serializable/relationship.rb', line 17 def as_jsonapi(included) {}.tap do |hash| hash[:links] = @_links if @_links.any? hash[:data] = linkage_data if included || @_include_linkage hash[:meta] = unless .nil? hash[:meta] = { included: false } if hash.empty? end 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.
27 28 29 |
# File 'lib/jsonapi/serializable/relationship.rb', line 27 def ||= Array(resources) end |