class Roby::Queries::MatcherBase

Attributes

neg_predicates[R]

Set of predicats that should be false for the object

The predicates are predicate method names (e.g. 'executable' for executable?)

@return [Array<Symbol>]

predicates[R]

Set of predicates that should be true for the object @return [Array<Symbol>]

Public Class Methods

match_predicate(name) click to toggle source
# 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) click to toggle source

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.

# File lib/roby/queries/matcher_base.rb, line 82
def match_predicates(*names)
    names.each do |name|
        match_predicate(name)
    end
end

Public Instance Methods

&(other) click to toggle source

AND-combination of two predicates

The returned task matcher will yield tasks that are matched by both predicates.

# File lib/roby/queries/matcher_base.rb, line 29
def &(other); AndMatcher.new(self, other) end
describe_failed_match(exception) click to toggle source

Describe a failed match in a human-readable way

It is meant to help debugging in tests

@return [nil,String]

# File lib/roby/queries/matcher_base.rb, line 103
def describe_failed_match(exception)
end
each(plan) { |t| ... } click to toggle source

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.

# 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?() click to toggle source

Returns true if calling filter with a task set and a relevant index will return the exact query result or not

# File lib/roby/queries/matcher_base.rb, line 6
def indexed_query?; false end
match() click to toggle source

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

# File lib/roby/queries/matcher_base.rb, line 94
def match
    self
end
negate() click to toggle source

Negates this predicate

The returned task matcher will yield tasks that are not matched by self

# File lib/roby/queries/matcher_base.rb, line 24
def negate; NotMatcher.new(self) end
|(other) click to toggle source

OR-combination of two predicates

The returned task matcher will yield tasks that match either one predicate or the other.

# File lib/roby/queries/matcher_base.rb, line 34
def |(other); OrMatcher.new(self, other) end