Sha256: b775247f4a36fff9b101ec6fc17f37f2da360c19ca9e5c0b4d84e62c17ae57b3

Contents?: true

Size: 616 Bytes

Versions: 3

Compression:

Stored size: 616 Bytes

Contents

module Chronicle
  module Schema
    module Validation
      class Validator
        def validate(data)
          type = data[:@type] || data['@type']
          raise Chronicle::Schema::ValidationError, 'Data does not contain a typed object' unless type

          contract = Chronicle::Schema::Validation.get_contract(type.to_sym)

          # binding.pry unless contract
          raise Chronicle::Schema::ValidationError, "#{type} is not a valid type" unless contract

          contract.new.call(data)
        end

        def self.call(data)
          new.validate(data)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chronicle-core-0.3.2 lib/chronicle/schema/validation/validator.rb
chronicle-core-0.3.1 lib/chronicle/schema/validation/validator.rb
chronicle-core-0.3.0 lib/chronicle/schema/validation/validator.rb