Class: Mountapi::Route::Response
- Inherits:
-
Object
- Object
- Mountapi::Route::Response
- Defined in:
- lib/mountapi/route/response.rb
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
- .build(status, schema = default_schema) ⇒ Object
-
.default_schema ⇒ Hash
The JSON API Schema to validate responses against.
Instance Method Summary collapse
-
#initialize(status, schema) ⇒ Response
constructor
A new instance of Response.
- #match?(other_status) ⇒ Boolean
- #schema ⇒ Object
Constructor Details
#initialize(status, schema) ⇒ Response
Returns a new instance of Response.
18 19 20 21 |
# File 'lib/mountapi/route/response.rb', line 18 def initialize(status, schema) @status = status @schema = schema end |
Instance Attribute Details
#status ⇒ Object (readonly)
Returns the value of attribute status.
4 5 6 |
# File 'lib/mountapi/route/response.rb', line 4 def status @status end |
Class Method Details
.build(status, schema = default_schema) ⇒ Object
14 15 16 |
# File 'lib/mountapi/route/response.rb', line 14 def self.build(status, schema = default_schema) new(status, Mountapi::Schema.build(schema)) end |
.default_schema ⇒ Hash
Returns the JSON API Schema to validate responses against.
6 7 8 9 10 11 12 |
# File 'lib/mountapi/route/response.rb', line 6 def self.default_schema @default_schema ||= OpenStruct.new({"type" => "object"}.merge( JSON.parse( File.read( File.("../response/json-api.json", __FILE__) )) )) end |
Instance Method Details
#match?(other_status) ⇒ Boolean
23 24 25 |
# File 'lib/mountapi/route/response.rb', line 23 def match?(other_status) status.to_s == other_status.to_s end |
#schema ⇒ Object
27 28 29 |
# File 'lib/mountapi/route/response.rb', line 27 def schema @schema || self.class.default_schema end |