Class: Constraint::SingleConstraint

Inherits:
Object
  • Object
show all
Defined in:
lib/constraint.rb

Overview

The base constraint class.

Instance Method Summary collapse

Constructor Details

#initialize(shell, name, description = nil, &block) ⇒ SingleConstraint

shell

The Shell class containing this constraint

name

This constraint’s name

description

Optional constraint description

block

The constraint that must evaluate to true in order for this constraint to succeed



32
33
34
35
36
# File 'lib/constraint.rb', line 32

def initialize(shell, name, description=nil, &block)
    # @other       = shell.constraints
    @name        = name
    @this        = block
end

Instance Method Details

#evaluate(invoker, object) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/constraint.rb', line 38

def evaluate(invoker, object)
    if @this.call(invoker, object)
        object
    else
        invoker.handle_constraint_violation(@name, object)
    end
end