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 = {}, 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 = {}, options = {}, &block)
  exposures.each { |k, v| instance_variable_set("@#{k}", v) }
  @_exposures = exposures
  @_options   = options
  @_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]  = @_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.



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

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