Class: ShafClient::Resource

Inherits:
BaseResource show all
Defined in:
lib/shaf_client/resource.rb

Direct Known Subclasses

Form

Instance Attribute Summary collapse

Attributes inherited from BaseResource

#attributes, #curies, #embedded_resources, #links

Instance Method Summary collapse

Methods inherited from BaseResource

#[], #actions, #attribute, #curie, #embedded, #link, #to_h, #to_s

Constructor Details

#initialize(client, payload, status = nil, headers = nil) ⇒ Resource

Returns a new instance of Resource.



8
9
10
11
12
13
# File 'lib/shaf_client/resource.rb', line 8

def initialize(client, payload, status = nil, headers = nil)
  @client = client
  @http_status = status
  @headers = headers
  super(payload)
end

Dynamic Method Handling

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

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/shaf_client/resource.rb', line 6

def headers
  @headers
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



6
7
8
# File 'lib/shaf_client/resource.rb', line 6

def http_status
  @http_status
end

Instance Method Details

#get_doc(rel:) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/shaf_client/resource.rb', line 23

def get_doc(rel:)
  rel = rel.to_s
  curie_name, rel =
    if rel.include? ':'
      rel.split(':')
    else
      [:doc, rel]
    end

  curie = curie(curie_name)
  uri = curie.resolve_templated(rel: rel)
  client.get_doc(uri)
end

#reload!Object



37
38
39
# File 'lib/shaf_client/resource.rb', line 37

def reload!
  self << get(:self, skip_cache: true)
end