Sha256: 8a774a9658243ca10b7448d3fe5f68293bba3c476250857f4e788ad4997f227d

Contents?: true

Size: 534 Bytes

Versions: 2

Compression:

Stored size: 534 Bytes

Contents

class Tram::Policy
  # @private
  class Validator
    attr_reader :name, :block, :stop_on_failure

    def ==(other)
      other.is_a?(self.class) && name && other.name == name
    end

    def check(object)
      name ? object.__send__(name) : object.instance_exec(&block)
    end

    private

    def initialize(name, block, stop_on_failure: false)
      @name  = name&.to_sym
      @block = block
      raise "Provide either method name or a block" unless !name ^ !block
      @stop_on_failure = stop_on_failure
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tram-policy-0.2.5 lib/tram/policy/validator.rb
tram-policy-0.2.4 lib/tram/policy/validator.rb