Sha256: 8481b12f40cfd60853c89c23fd8aa6c8b4d3af05e669ab8e9dd940935c73584a

Contents?: true

Size: 709 Bytes

Versions: 2

Compression:

Stored size: 709 Bytes

Contents

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

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

    def check(object)
      object.__send__ :instance_variable_set, :@__scope__, scope
      name ? object.__send__(name) : object.instance_exec(&block)
    rescue
      object.__send__ :instance_variable_set, :@__scope__, nil
    end

    private

    def initialize(scope, name, block, stop_on_failure: false)
      @scope = scope
      @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.2 lib/tram/policy/validator.rb
tram-policy-0.2.1 lib/tram/policy/validator.rb