Class: Predicated::Constraints

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

Instance Method Summary collapse

Constructor Details

#initializeConstraints

Returns a new instance of Constraints.



5
6
7
# File 'lib/predicated/constrain.rb', line 5

def initialize
  @constraints = []
end

Instance Method Details

#==(other) ⇒ Object



28
29
30
# File 'lib/predicated/constrain.rb', line 28

def ==(other)
  @constraints == other.instance_variable_get("@constraints".to_sym)
end

#add(constraint) ⇒ Object



9
10
11
12
# File 'lib/predicated/constrain.rb', line 9

def add(constraint)
  @constraints << constraint
  self
end

#check(whole_predicate) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/predicated/constrain.rb', line 14

def check(whole_predicate)
  result = ConstraintCheckResult.new
  
  @constraints.collect do |constraint|
    whole_predicate.select(*constraint.selectors).collect do |predicate, ancestors|
      if ! constraint.check(predicate, ancestors)
        result.violation(constraint, predicate)
      end
    end
  end
  
  result
end