Class: Mountapi::Route::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/mountapi/route/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#statusObject (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_schemaHash

Returns the JSON API Schema to validate responses against.

Returns:

  • (Hash)

    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.expand_path("../response/json-api.json", __FILE__)
    ))
  ))
end

Instance Method Details

#match?(other_status) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/mountapi/route/response.rb', line 23

def match?(other_status)
  status.to_s == other_status.to_s
end

#schemaObject



27
28
29
# File 'lib/mountapi/route/response.rb', line 27

def schema
  @schema || self.class.default_schema
end