Class: Roby::Queries::MatcherBase
- Defined in:
- lib/roby/queries/matcher_base.rb
Direct Known Subclasses
AndMatcher, LocalizedErrorMatcher, NotMatcher, OrMatcher, PlanObjectMatcher
Instance Attribute Summary collapse
-
#neg_predicates ⇒ Array<Symbol>
readonly
Set of predicats that should be false for the object.
-
#predicates ⇒ Array<Symbol>
readonly
Set of predicates that should be true for the object.
Class Method Summary collapse
-
.declare_class_methods(*names) ⇒ Object
:nodoc:.
- .match_predicate(name) ⇒ Object
-
.match_predicates(*names) ⇒ Object
For each name in
names, define a #name and a #not_name method.
Instance Method Summary collapse
-
#&(other) ⇒ Object
AND-combination of two predicates .
-
#describe_failed_match(exception) ⇒ nil, String
Describe a failed match in a human-readable way.
-
#each(plan) ⇒ Object
Enumerates all tasks of
planwhich match this TaskMatcher object. -
#indexed_query? ⇒ Boolean
Returns true if calling #filter with a task set and a relevant index will return the exact query result or not.
-
#match ⇒ Object
The #match method is used to convert any object to the corresponding Query object.
-
#negate ⇒ Object
Negates this predicate.
-
#|(other) ⇒ Object
OR-combination of two predicates .
Instance Attribute Details
#neg_predicates ⇒ Array<Symbol> (readonly)
Set of predicats that should be false for the object
The predicates are predicate method names (e.g. ‘executable’ for #executable?)
45 46 47 |
# File 'lib/roby/queries/matcher_base.rb', line 45 def neg_predicates @neg_predicates end |
#predicates ⇒ Array<Symbol> (readonly)
Set of predicates that should be true for the object
38 39 40 |
# File 'lib/roby/queries/matcher_base.rb', line 38 def predicates @predicates end |
Class Method Details
.declare_class_methods(*names) ⇒ Object
:nodoc:
48 49 50 51 52 53 54 55 |
# File 'lib/roby/queries/matcher_base.rb', line 48 def declare_class_methods(*names) # :nodoc: names.each do |name| raise "no instance method #{name} on #{self}" unless method_defined?(name) singleton_class.send(:define_method, name) do |*args| self.new.send(name, *args) end end end |
.match_predicate(name) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/roby/queries/matcher_base.rb', line 57 def match_predicate(name) method_name = name.to_s.gsub(/\?$/, '') class_eval <<-EOD, __FILE__, __LINE__+1 def #{method_name} if neg_predicates.include?(:#{name}) raise ArgumentError, "trying to match (#{name} & !#{name})" end predicates << :#{name} self end def not_#{method_name} if predicates.include?(:#{name}) raise ArgumentError, "trying to match (#{name} & !#{name})" end neg_predicates << :#{name} self end EOD declare_class_methods(method_name, "not_#{method_name}") end |
.match_predicates(*names) ⇒ Object
For each name in names, define a #name and a #not_name method. If the first is called, the matcher will match only tasks whose #name? method returns true. If the second is called, the opposite will be done.
82 83 84 85 86 |
# File 'lib/roby/queries/matcher_base.rb', line 82 def match_predicates(*names) names.each do |name| match_predicate(name) end end |
Instance Method Details
#&(other) ⇒ Object
AND-combination of two predicates
The returned task matcher will yield tasks that are matched by both predicates.
29 |
# File 'lib/roby/queries/matcher_base.rb', line 29 def &(other); AndMatcher.new(self, other) end |
#describe_failed_match(exception) ⇒ nil, String
Describe a failed match in a human-readable way
It is meant to help debugging in tests
103 104 |
# File 'lib/roby/queries/matcher_base.rb', line 103 def describe_failed_match(exception) end |
#each(plan) ⇒ Object
Enumerates all tasks of plan which match this TaskMatcher object
It is O(N). You should prefer use Query which uses the plan’s task indexes, thus leading to O(1) in simple cases.
12 13 14 15 16 17 18 |
# File 'lib/roby/queries/matcher_base.rb', line 12 def each(plan) return enum_for(__method__, plan) if !block_given? plan.each_task do |t| yield(t) if self === t end self end |
#indexed_query? ⇒ Boolean
Returns true if calling #filter with a task set and a relevant index will return the exact query result or not
6 |
# File 'lib/roby/queries/matcher_base.rb', line 6 def indexed_query?; false end |
#match ⇒ Object
The #match method is used to convert any object to the corresponding Query object. For instance, Models::TaskEvent#match returns the corresponding TaskEventGeneratorMatcher.
For matchers, it returns self
94 95 96 |
# File 'lib/roby/queries/matcher_base.rb', line 94 def match self end |
#negate ⇒ Object
Negates this predicate
The returned task matcher will yield tasks that are not matched by self
24 |
# File 'lib/roby/queries/matcher_base.rb', line 24 def negate; NotMatcher.new(self) end |