Class: JSONAPI::Serializable::Resource::Relationship

Inherits:
Object
  • Object
show all
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

Methods included from DSL

#data, #link, #linkage

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 = {}, 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



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

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

#metaObject

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
  @_meta
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.



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

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

#resourcesObject

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