Class: Lurker::Json::ResponseCodes

Inherits:
Schema
  • Object
show all
Defined in:
lib/lurker/json/schema/response_codes.rb

Constant Summary collapse

STATUS =
'status'.freeze
SUCCESSFUL =
'successful'.freeze

Constants inherited from Schema

Schema::EXTENSIONS, Schema::REQUEST_PARAMETERS, Schema::RESPONSE_CODES, Schema::RESPONSE_PARAMETERS

Instance Attribute Summary

Attributes inherited from Schema

#parent_property, #parent_schema, #root_schema, #uri

Instance Method Summary collapse

Methods inherited from Schema

#documentation, #documentation_uri, #method_missing, #reorder!, #replace!, #respond_to_missing?, #root?, #to_hash, #to_json, #to_yaml

Methods included from Concerns::Validatable

#to_validation_schema, #validate

Constructor Details

#initialize(schema, options = {}) ⇒ ResponseCodes

Returns a new instance of ResponseCodes.



7
8
9
10
11
# File 'lib/lurker/json/schema/response_codes.rb', line 7

def initialize(schema, options = {})
  @parent_property = 'responseCodes'

  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Lurker::Json::Schema

Instance Method Details

#exists?(status_code, successful) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'lib/lurker/json/schema/response_codes.rb', line 29

def exists?(status_code, successful)
  !!@schema.detect do |response_code|
    response_code[SUCCESSFUL] == successful &&
      (response_code[STATUS] == status_code ||    # 200
       response_code[STATUS].to_i == status_code) # "200 OK"
  end
end

#merge!(status_code, successful) ⇒ Object



13
14
15
16
17
18
# File 'lib/lurker/json/schema/response_codes.rb', line 13

def merge!(status_code, successful)
  return if exists?(status_code, successful)

  payload = {STATUS => status_code, SUCCESSFUL => successful, Json::DESCRIPTION => ''}
  @schema << Lurker::Json::Parser.plain(root_schema: root_schema).parse(payload)
end

#validate!(status_code, successful) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/lurker/json/schema/response_codes.rb', line 20

def validate!(status_code, successful)
  return if exists?(status_code, successful)

  raise Lurker::UndocumentedResponseCode,
    'Undocumented response: %s, successful: %s' % [
      status_code, successful
    ]
end