Class: Roby::Query
- Inherits:
-
TaskMatcher
- Object
- TaskMatcher
- Roby::Query
- Includes:
- Enumerable
- Defined in:
- lib/roby/query.rb,
lib/roby/distributed/protocol.rb
Overview
A query is a predicate on both the task internal properties, and their plan-related properties as well.
Defined Under Namespace
Classes: DRoby
Constant Summary
Constants inherited from TaskMatcher
Instance Attribute Summary collapse
-
#neg_plan_predicates ⇒ Object
readonly
The set of predicates of Plan which must return false for #=== to return true.
-
#plan ⇒ Object
readonly
The plan this query acts on.
-
#plan_predicates ⇒ Object
readonly
The set of predicates of Plan which must return true for #=== to return true.
Attributes inherited from TaskMatcher
#arguments, #improved_information, #model, #needed_information, #neg_predicates, #owners, #predicates
Class Method Summary collapse
-
.match_plan_predicates(*names) ⇒ Object
For each name in
names, define the #name and #not_name methods on Query objects.
Instance Method Summary collapse
-
#===(task) ⇒ Object
True if
taskmatches the query. -
#droby_dump(dest) ⇒ Object
Returns an intermediate representation of
selfsuitable to be sent to thedestpeer. -
#each(&block) ⇒ Object
Iterates on all the tasks in the given plan which match the query.
-
#initialize(plan) ⇒ Query
constructor
Create a query object on the given plan.
-
#reset ⇒ Object
#result_set is a cached value.
-
#result_set ⇒ Object
The set of tasks which match in plan.
-
#roots(relation) ⇒ Object
Returns the set of tasks from the query for which no parent in
relationcan be found in the query itself.
Methods included from Enumerable
Methods inherited from TaskMatcher
#&, declare_class_methods, #filter, match_predicates, #negate, #owned_by, #self_owned, #which_fullfills, #which_improves, #which_needs, #with_arguments, #with_model, #with_model_arguments, #|
Constructor Details
Instance Attribute Details
#neg_plan_predicates ⇒ Object (readonly)
The set of predicates of Plan which must return false for #=== to return true.
248 249 250 |
# File 'lib/roby/query.rb', line 248 def neg_plan_predicates @neg_plan_predicates end |
#plan ⇒ Object (readonly)
The plan this query acts on
219 220 221 |
# File 'lib/roby/query.rb', line 219 def plan @plan end |
#plan_predicates ⇒ Object (readonly)
The set of predicates of Plan which must return true for #=== to return true
245 246 247 |
# File 'lib/roby/query.rb', line 245 def plan_predicates @plan_predicates end |
Class Method Details
.match_plan_predicates(*names) ⇒ Object
For each name in names, define the #name and #not_name methods on Query objects. When one of these methods is called on a Query object, plan.name?(task) must return true (resp. false) for the task to match.
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/roby/query.rb', line 255 def match_plan_predicates(*names) names.each do |name| class_eval <<-EOD def #{name} if neg_plan_predicates.include?(:#{name}?) raise ArgumentError, "trying to match (#{name}? & !#{name}?)" end plan_predicates << :#{name}? self end def not_#{name} if plan_predicates.include?(:#{name}?) raise ArgumentError, "trying to match (#{name}? & !#{name}?)" end neg_plan_predicates << :#{name}? self end EOD end end |
Instance Method Details
#===(task) ⇒ Object
True if task matches the query. Call #result_set to have the set of tasks which match in the given plan.
287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/roby/query.rb', line 287 def ===(task) return unless super for pred in plan_predicates return unless plan.send(pred, task) end for neg_pred in neg_plan_predicates return if plan.send(neg_pred, task) end true end |
#droby_dump(dest) ⇒ Object
Returns an intermediate representation of self suitable to be sent to the dest peer.
193 194 195 196 |
# File 'lib/roby/distributed/protocol.rb', line 193 def droby_dump(dest) marshalled_matcher = super DRoby.new(plan_predicates, neg_plan_predicates, marshalled_matcher.args) end |
#each(&block) ⇒ Object
Iterates on all the tasks in the given plan which match the query
300 301 302 303 |
# File 'lib/roby/query.rb', line 300 def each(&block) plan.query_each(result_set, &block) self end |
#reset ⇒ Object
#result_set is a cached value. Call this method to reinitialize, making sure the result set is recomputed next time #result_set is called.
238 239 240 241 |
# File 'lib/roby/query.rb', line 238 def reset @result_set = nil self end |