Sha256: dcd2fd8e8d56bbdc92f4d6d52cab941d51eaa966ab8155b90ac1457a85ed7898

Contents?: true

Size: 774 Bytes

Versions: 1

Compression:

Stored size: 774 Bytes

Contents

module Mountapi
  module Route
    class Response
      attr_reader :status
      # @return [Hash] the JSON API Schema to validate responses against
      def self.default_schema
        @default_schema ||= OpenStruct.new({"type" => "object"}.merge( JSON.parse(
          File.read(
            File.expand_path("../response/json-api.json", __FILE__)
          ))
        ))
      end

      def self.build(status, schema = default_schema)
        new(status, Mountapi::Schema.build(schema))
      end

      def initialize(status, schema)
        @status = status
        @schema = schema
      end

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mountapi-0.11.1 lib/mountapi/route/response.rb