Class: ShafClient::AlpsJson

Inherits:
Resource show all
Defined in:
lib/shaf_client/alps_json.rb

Constant Summary

Constants included from MimeTypes

MimeTypes::MIME_TYPE_ALPS_JSON, MimeTypes::MIME_TYPE_HAL, MimeTypes::MIME_TYPE_JSON, MimeTypes::MIME_TYPE_PROBLEM_JSON

Instance Attribute Summary collapse

Attributes inherited from Resource

#headers, #http_status

Attributes inherited from BaseResource

#attributes, #curies, #embedded_resources, #links

Instance Method Summary collapse

Methods inherited from Resource

build, content_type, #content_type, default_resource_class!, #destroy!, #get, #get_doc, #get_hal_form, #inspect, profile, #reload!

Methods inherited from BaseResource

#[], #actions, #attribute, #curie, #embedded, #inspect, #link, #rel?, #to_s

Constructor Details

#initialize(_client, payload, status = nil, headers = {}) ⇒ AlpsJson

Returns a new instance of AlpsJson.



9
10
11
12
13
14
15
# File 'lib/shaf_client/alps_json.rb', line 9

def initialize(_client, payload, status = nil, headers = {})
  super

  @links = {}.freeze
  @curies = {}.freeze
  @embedded_resources = {}.freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ShafClient::BaseResource

Instance Attribute Details

#descriptorsObject (readonly)

Returns the value of attribute descriptors.



7
8
9
# File 'lib/shaf_client/alps_json.rb', line 7

def descriptors
  @descriptors
end

Instance Method Details

#descriptor(id) ⇒ Object



23
24
25
# File 'lib/shaf_client/alps_json.rb', line 23

def descriptor(id)
  descriptors.find { |desc| desc.id == id.to_sym }
end

#each_descriptor(&block) ⇒ Object



27
28
29
# File 'lib/shaf_client/alps_json.rb', line 27

def each_descriptor(&block)
  descriptors.each(&block)
end

#to_hObject



17
18
19
20
21
# File 'lib/shaf_client/alps_json.rb', line 17

def to_h
  attributes.merge(
    descriptors: descriptors.map(&:to_h)
  )
end