Sha256: a2edcd69275c129eef1af5ea61903a5d15d1500e25151f76235855af17c85a7c

Contents?: true

Size: 732 Bytes

Versions: 33

Compression:

Stored size: 732 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

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

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
fitting-2.18.3 lib/fitting/response/fully_validates.rb
fitting-2.18.2 lib/fitting/response/fully_validates.rb
fitting-2.18.1 lib/fitting/response/fully_validates.rb
fitting-2.18.0 lib/fitting/response/fully_validates.rb
fitting-2.17.0 lib/fitting/response/fully_validates.rb
fitting-2.16.1 lib/fitting/response/fully_validates.rb
fitting-2.16.0 lib/fitting/response/fully_validates.rb
fitting-2.15.0 lib/fitting/response/fully_validates.rb
fitting-2.14.1 lib/fitting/response/fully_validates.rb
fitting-2.14.0 lib/fitting/response/fully_validates.rb
fitting-2.13.1 lib/fitting/response/fully_validates.rb
fitting-2.13.0 lib/fitting/response/fully_validates.rb
fitting-2.12.1 lib/fitting/response/fully_validates.rb
fitting-2.12.0 lib/fitting/response/fully_validates.rb
fitting-2.11.0 lib/fitting/response/fully_validates.rb
fitting-2.10.0 lib/fitting/response/fully_validates.rb
fitting-2.9.1 lib/fitting/response/fully_validates.rb
fitting-2.9.0 lib/fitting/response/fully_validates.rb
fitting-2.8.1 lib/fitting/response/fully_validates.rb
fitting-2.8.0 lib/fitting/response/fully_validates.rb