Class: Committee::Drivers::HyperSchema::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/committee/drivers/hyper_schema/link.rb

Overview

Link abstracts an API link specifically for JSON hyper-schema.

For most operations, it’s a simple pass through to a JsonSchema::Schema::Link, but implements some exotic behavior in a few places.

Instance Method Summary collapse

Constructor Details

#initialize(hyper_schema_link) ⇒ Link

Returns a new instance of Link.



12
13
14
# File 'lib/committee/drivers/hyper_schema/link.rb', line 12

def initialize(hyper_schema_link)
  @hyper_schema_link = hyper_schema_link
end

Instance Method Details

#enc_typeObject

The link’s input media type. i.e. How requests should be encoded.



17
18
19
# File 'lib/committee/drivers/hyper_schema/link.rb', line 17

def enc_type
  hyper_schema_link.enc_type
end

#hrefObject



21
22
23
# File 'lib/committee/drivers/hyper_schema/link.rb', line 21

def href
  hyper_schema_link.href
end

#media_typeObject

The link’s output media type. i.e. How responses should be encoded.



26
27
28
# File 'lib/committee/drivers/hyper_schema/link.rb', line 26

def media_type
  hyper_schema_link.media_type
end

#methodObject



30
31
32
# File 'lib/committee/drivers/hyper_schema/link.rb', line 30

def method
  hyper_schema_link.method
end

#parentObject

Passes through a link’s parent resource. Note that this is not part of the Link interface and is here to support a legacy Heroku-ism behavior that allowed a link tagged with rel=instances to imply that a list will be returned.



38
39
40
# File 'lib/committee/drivers/hyper_schema/link.rb', line 38

def parent
  hyper_schema_link.parent
end

#relObject



42
43
44
# File 'lib/committee/drivers/hyper_schema/link.rb', line 42

def rel
  hyper_schema_link.rel
end

#schemaObject

The link’s input schema. i.e. How we validate an endpoint’s incoming parameters.



48
49
50
# File 'lib/committee/drivers/hyper_schema/link.rb', line 48

def schema
  hyper_schema_link.schema
end

#status_successObject



52
53
54
# File 'lib/committee/drivers/hyper_schema/link.rb', line 52

def status_success
  hyper_schema_link.rel == "create" ? 201 : 200
end

#target_schemaObject

The link’s output schema. i.e. How we validate an endpoint’s response data.



58
59
60
# File 'lib/committee/drivers/hyper_schema/link.rb', line 58

def target_schema
  hyper_schema_link.target_schema
end