Sha256: 7602b500e1aa312b3af03d96819d59a30c814cd22447b1f775b50e835ecf9d43

Contents?: true

Size: 570 Bytes

Versions: 17

Compression:

Stored size: 570 Bytes

Contents

module Datacaster
  class Comparator < Base
    def initialize(value, error_key = nil)
      @value = value

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

    def cast(object, runtime:)
      if @value == object
        Datacaster.ValidResult(object)
      else
        Datacaster.ErrorResult(
          I18nValues::Key.new(@error_keys, reference: @value.inspect, value: object)
        )
      end
    end

    def inspect
      "#<Datacaster::Comparator(#{@value.inspect})>"
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

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