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.



68
69
70
# File 'lib/committee/drivers/hyper_schema.rb', line 68

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.



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

def enc_type
  hyper_schema_link.enc_type
end

#hrefObject



77
78
79
# File 'lib/committee/drivers/hyper_schema.rb', line 77

def href
  hyper_schema_link.href
end

#media_typeObject

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



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

def media_type
  hyper_schema_link.media_type
end

#methodObject



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

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.



94
95
96
# File 'lib/committee/drivers/hyper_schema.rb', line 94

def parent
  hyper_schema_link.parent
end

#relObject



98
99
100
# File 'lib/committee/drivers/hyper_schema.rb', line 98

def rel
  hyper_schema_link.rel
end

#schemaObject

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



104
105
106
# File 'lib/committee/drivers/hyper_schema.rb', line 104

def schema
  hyper_schema_link.schema
end

#status_successObject



108
109
110
# File 'lib/committee/drivers/hyper_schema.rb', line 108

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.



114
115
116
# File 'lib/committee/drivers/hyper_schema.rb', line 114

def target_schema
  hyper_schema_link.target_schema
end