Class: JSONAPI::Serializable::Relationship

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/jsonapi/serializable/relationship.rb,
lib/jsonapi/serializable/relationship/dsl.rb

Defined Under Namespace

Modules: DSL

Instance Method Summary collapse

Methods included from DSL

#data, #link, #linkage, #meta

Constructor Details

#initialize(exposures = {}, &block) ⇒ Relationship

Returns a new instance of Relationship.



9
10
11
12
13
14
# 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



16
17
18
19
20
21
22
23
# File 'lib/jsonapi/serializable/relationship.rb', line 16

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

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.



26
27
28
# File 'lib/jsonapi/serializable/relationship.rb', line 26

def related_resources
  @_related_resources ||= Array(resources)
end