Class: Roby::EventConstraints::Explanation
- Defined in:
- lib/roby/event_constraints.rb
Overview
An explanation for a given predicate value. predicate
is the predicate, elements
the explanations for predicate
having reached the value.
elements
is an array of Event and EventGenerator instances.
If an Event is stored there, the explanation is that this event has been emitted.
If an EventGenerator is stored there, the reason depends on value
. If value
is nil (static), the reason is that the generator is unreachable. If value
is false (not emitted), it is that the generator did not emit.
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
The elements of explanation.
-
#predicate ⇒ Object
readonly
The predicate that we are providing an explanation for.
-
#value ⇒ Object
Representation of what is being explained.
Instance Method Summary collapse
-
#initialize(value, predicate, elements) ⇒ Explanation
constructor
A new instance of Explanation.
- #pretty_print(pp, context_task: nil) ⇒ Object
- #report_exceptions_on(e) ⇒ Object
- #simple? ⇒ Boolean
Constructor Details
#initialize(value, predicate, elements) ⇒ Explanation
Returns a new instance of Explanation.
308 309 310 311 312 |
# File 'lib/roby/event_constraints.rb', line 308 def initialize(value, predicate, elements) @value = value @predicate = predicate @elements = elements end |
Instance Attribute Details
#elements ⇒ Object (readonly)
The elements of explanation
302 303 304 |
# File 'lib/roby/event_constraints.rb', line 302 def elements @elements end |
#predicate ⇒ Object (readonly)
The predicate that we are providing an explanation for
300 301 302 |
# File 'lib/roby/event_constraints.rb', line 300 def predicate @predicate end |
#value ⇒ Object
Representation of what is being explained. It is true if it is explaining why a predicate is true, false if it is explaining why it is false and nil for static.
298 299 300 |
# File 'lib/roby/event_constraints.rb', line 298 def value @value end |
Instance Method Details
#pretty_print(pp, context_task: nil) ⇒ Object
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/roby/event_constraints.rb', line 331 def pretty_print(pp, context_task: nil) if value == false predicate.pretty_print(pp) pp.text " is false" elsif value == true predicate.pretty_print(pp) pp.text " is true" elsif value.nil? pp.text "the value of " predicate.pretty_print(pp) pp.text " will not change anymore" end pp.nest(2) do elements.each do |explanation| pp.breakable case explanation when Event pp.text "the following event has been emitted:" when EventGenerator if value.nil? pp.text "the following event is unreachable:" elsif value == true pp.text "the following event is reachable, "\ "but has not been emitted:" else pp.text "the following event has been emitted:" end end pp.breakable explanation.pretty_print( pp, context_task: context_task ) case explanation when Event sources = explanation.all_sources unless sources.empty? pp.breakable pp.breakable pp.text "The emission was caused by the following events" sources.each do |ev| pp.breakable pp.text "< " ev.pretty_print( pp, context: false, context_task: context_task ) end end when EventGenerator if value.nil? && explanation.unreachability_reason pp.breakable pp.breakable pp.text "The unreachability was caused by" pp.nest(2) do pp.breakable explanation.unreachability_reason.pretty_print(pp) end end else explanation.pretty_print(pp) end end end end |
#report_exceptions_on(e) ⇒ Object
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/roby/event_constraints.rb', line 314 def report_exceptions_on(e) elements.each do |el| case el when Explanation el.report_exceptions_on(e) when Exception e.report_exceptions_from(el) when Event el.all_sources.each do |ev| e.report_exceptions_from(ev) end when EventGenerator e.report_exceptions_from(el.unreachability_reason) if value.nil? end end end |
#simple? ⇒ Boolean
304 305 306 |
# File 'lib/roby/event_constraints.rb', line 304 def simple? elements.size == 1 && !elements.first.kind_of?(Explanation) end |