Sha256: 57646b4531a9396ace65cacc28b4b85f2c2ea3a4b4c85228b0bbd6f54e0a3ca2

Contents?: true

Size: 715 Bytes

Versions: 2

Compression:

Stored size: 715 Bytes

Contents

require 'json-schema'

module Fitting
  class Response
    class FullyValidates < Array
      def self.craft(schemas, body, strict)
        if schemas
          new(schemas.inject([]) do |res, schema|
            res.push(fully_validate(schema, body, strict))
          end)
        else
          @valid = false
          new
        end
      end

      def valid?
        @valid ||= any? { |fully_validate| fully_validate == [] }
      end

      def to_s
        @to_s ||= join("\n\n")
      end

      private

      def self.fully_validate(schema, body, strict)
        JSON::Validator.fully_validate(schema, body, :strict => strict)
      rescue JSON::Schema::UriError
        []
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fitting-2.0.3 lib/fitting/response/fully_validates.rb
fitting-2.0.2 lib/fitting/response/fully_validates.rb