Sha256: daf7d933517283261686d69e2c0dd153984932956d008ca3400ed210ce8108df

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

module Lurker
  module Json
    class ResponseCodes < Schema
      STATUS = 'status'.freeze
      SUCCESSFUL = 'successful'.freeze

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

        super
      end

      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

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

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

      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
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
lurker-1.0.0 lib/lurker/json/schema/response_codes.rb
lurker-0.6.12 lib/lurker/json/schema/response_codes.rb
lurker-0.6.11 lib/lurker/json/schema/response_codes.rb
lurker-0.6.10 lib/lurker/json/schema/response_codes.rb
lurker-0.6.9 lib/lurker/json/schema/response_codes.rb
lurker-0.6.8 lib/lurker/json/schema/response_codes.rb
lurker-0.6.7 lib/lurker/json/schema/response_codes.rb
lurker-0.6.6 lib/lurker/json/schema/response_codes.rb
lurker-0.6.5 lib/lurker/json/schema/response_codes.rb
lurker-0.6.4 lib/lurker/json/schema/response_codes.rb