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

Inherits:
Object
  • Object
show all
Defined in:
lib/committee/drivers/hyper_schema.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.



56
57
58
# File 'lib/committee/drivers/hyper_schema.rb', line 56

def initialize(hyper_schema_link)
  self.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.



61
62
63
# File 'lib/committee/drivers/hyper_schema.rb', line 61

def enc_type
  hyper_schema_link.enc_type
end

#hrefObject



65
66
67
# File 'lib/committee/drivers/hyper_schema.rb', line 65

def href
  hyper_schema_link.href
end

#media_typeObject

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



70
71
72
# File 'lib/committee/drivers/hyper_schema.rb', line 70

def media_type
  hyper_schema_link.media_type
end

#methodObject



74
75
76
# File 'lib/committee/drivers/hyper_schema.rb', line 74

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.



82
83
84
# File 'lib/committee/drivers/hyper_schema.rb', line 82

def parent
  hyper_schema_link.parent
end

#relObject



86
87
88
# File 'lib/committee/drivers/hyper_schema.rb', line 86

def rel
  hyper_schema_link.rel
end

#schemaObject

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



92
93
94
# File 'lib/committee/drivers/hyper_schema.rb', line 92

def schema
  hyper_schema_link.schema
end

#status_successObject



96
97
98
# File 'lib/committee/drivers/hyper_schema.rb', line 96

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.



102
103
104
# File 'lib/committee/drivers/hyper_schema.rb', line 102

def target_schema
  hyper_schema_link.target_schema
end