Sha256: d042fdd5d43c1372772788b065faa6201954b6571d074db75e4055ebb51cd3f4

Contents?: true

Size: 569 Bytes

Versions: 18

Compression:

Stored size: 569 Bytes

Contents

module Datacaster
  class Checker < Base
    def initialize(error_key = nil, &block)
      raise "Expected block" unless block_given?

      @error_keys = ['.check', 'datacaster.errors.check']
      @error_keys.unshift(error_key) if error_key

      @check = block
    end

    def cast(object, runtime:)
      if Runtimes::Base.(runtime, @check, object)
        Datacaster.ValidResult(object)
      else
        Datacaster.ErrorResult(I18nValues::Key.new(@error_keys, value: object))
      end
    end

    def inspect
      "#<Datacaster::Checker>"
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
datacaster-4.1.0 lib/datacaster/checker.rb
datacaster-4.0.1 lib/datacaster/checker.rb
datacaster-3.3.1 lib/datacaster/checker.rb
datacaster-3.3.0 lib/datacaster/checker.rb
datacaster-3.2.7 lib/datacaster/checker.rb
datacaster-3.2.6 lib/datacaster/checker.rb
datacaster-3.2.5 lib/datacaster/checker.rb
datacaster-3.2.4 lib/datacaster/checker.rb
datacaster-3.2.3 lib/datacaster/checker.rb
datacaster-3.2.2 lib/datacaster/checker.rb
datacaster-3.2.1 lib/datacaster/checker.rb
datacaster-3.2.0 lib/datacaster/checker.rb
datacaster-3.1.5 lib/datacaster/checker.rb
datacaster-3.1.3 lib/datacaster/checker.rb
datacaster-3.1.2 lib/datacaster/checker.rb
datacaster-3.1.1 lib/datacaster/checker.rb
datacaster-3.1.0 lib/datacaster/checker.rb
datacaster-3.0.0 lib/datacaster/checker.rb