Class: Constraint::NilConstraint
- Inherits:
-
Object
- Object
- Constraint::NilConstraint
- Defined in:
- lib/constraint.rb
Overview
The base constraint class. Always evaluates to true.
Direct Known Subclasses
Instance Method Summary collapse
-
#evaluate(object) ⇒ Object
Return true if
argscomplies with @this constraint. -
#handle_violation(object) ⇒ Object
Delegate to Shell#handle_constraint_violation.
-
#initialize(shell, name, description = nil, &block) ⇒ NilConstraint
constructor
- 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.
Constructor Details
#initialize(shell, name, description = nil, &block) ⇒ NilConstraint
- 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
27 28 29 30 31 32 33 |
# File 'lib/constraint.rb', line 27 def initialize(shell, name, description=nil, &block) @shell = shell @other = shell.constraints @name = name @description = description @this = block end |
Instance Method Details
#evaluate(object) ⇒ Object
Return true if args complies with @this constraint.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/constraint.rb', line 36 def evaluate(object) begin rv = @this.call(object) rescue Exception => e @shell.log_constraint_exception(e) end begin if @other return evaluate_control(rv, object) elsif rv return object else return evaluate(handle_violation(object)) end rescue ConstraintViolation => e raise e end end |
#handle_violation(object) ⇒ Object
Delegate to Shell#handle_constraint_violation.
56 57 58 |
# File 'lib/constraint.rb', line 56 def handle_violation(object) return @shell.handle_constraint_violation(@name, object) end |