Class: Patir::CommandSequenceStatus
- Inherits:
-
Object
- Object
- Patir::CommandSequenceStatus
- Defined in:
- lib/patir/command.rb
Overview
CommandSequenceStatus represents the status of a CommandSequence, including the status of all the steps for this sequence.
In order to extract the status from steps, classes should quack to the rythm of Command. CommandSequenceStatus does this, so you can nest Stati
The status of an action sequence is :not_executed, :running, :success, :warning or :error and represents the overall status :not_executed is set when all steps are :not_executed :running is set while the sequence is running. Upon completion or interruption one of :success, :error or :warning will be set. :success is set when all steps are succesfull. :warning is set when at least one step generates warnings and there are no failures. :error is set when after execution at least one step has the :error status
Instance Attribute Summary collapse
-
#sequence_id ⇒ Object
Returns the value of attribute sequence_id.
-
#sequence_name ⇒ Object
Returns the value of attribute sequence_name.
-
#sequence_runner ⇒ Object
Returns the value of attribute sequence_runner.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#status ⇒ Object
Returns the value of attribute status.
-
#step_states ⇒ Object
Returns the value of attribute step_states.
-
#stop_time ⇒ Object
Returns the value of attribute stop_time.
-
#strategy ⇒ Object
Returns the value of attribute strategy.
Instance Method Summary collapse
-
#completed? ⇒ Boolean
A sequence is considered completed when:.
- #error ⇒ Object
- #exec_time ⇒ Object
- #executed? ⇒ Boolean
-
#initialize(sequence_name, steps = nil) ⇒ CommandSequenceStatus
constructor
You can pass an array of Commands to initialize CommandSequenceStatus.
- #name ⇒ Object
- #number ⇒ Object
- #output ⇒ Object
- #running? ⇒ Boolean
-
#step=(step) ⇒ Object
Adds a step to the state.
-
#step_state(number) ⇒ Object
A nil means there is no step with that number.
-
#success? ⇒ Boolean
true is returned when all steps were succesfull.
-
#summary ⇒ Object
produces a brief text summary for this status.
- #to_s ⇒ Object
Constructor Details
#initialize(sequence_name, steps = nil) ⇒ CommandSequenceStatus
You can pass an array of Commands to initialize CommandSequenceStatus
341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/patir/command.rb', line 341 def initialize sequence_name,steps=nil @sequence_name=sequence_name @sequence_runner="" @sequence_id=nil @step_states||=Hash.new #not run yet @status=:not_executed #translate the array of steps as we need it in number=>state form steps.each{|step| self.step=step } if steps @start_time=Time.now end |
Instance Attribute Details
#sequence_id ⇒ Object
Returns the value of attribute sequence_id.
339 340 341 |
# File 'lib/patir/command.rb', line 339 def sequence_id @sequence_id end |
#sequence_name ⇒ Object
Returns the value of attribute sequence_name.
339 340 341 |
# File 'lib/patir/command.rb', line 339 def sequence_name @sequence_name end |
#sequence_runner ⇒ Object
Returns the value of attribute sequence_runner.
339 340 341 |
# File 'lib/patir/command.rb', line 339 def sequence_runner @sequence_runner end |
#start_time ⇒ Object
Returns the value of attribute start_time.
339 340 341 |
# File 'lib/patir/command.rb', line 339 def start_time @start_time end |
#status ⇒ Object
Returns the value of attribute status.
339 340 341 |
# File 'lib/patir/command.rb', line 339 def status @status end |
#step_states ⇒ Object
Returns the value of attribute step_states.
339 340 341 |
# File 'lib/patir/command.rb', line 339 def step_states @step_states end |
#stop_time ⇒ Object
Returns the value of attribute stop_time.
339 340 341 |
# File 'lib/patir/command.rb', line 339 def stop_time @stop_time end |
#strategy ⇒ Object
Returns the value of attribute strategy.
339 340 341 |
# File 'lib/patir/command.rb', line 339 def strategy @strategy end |
Instance Method Details
#completed? ⇒ Boolean
A sequence is considered completed when:
a step has errors and the :fail_on_error strategy is used
a step has warnings and the :fail_on_warning strategy is used
in all other cases if none of the steps has a :not_executed or :running status
369 370 371 372 373 374 375 376 377 378 |
# File 'lib/patir/command.rb', line 369 def completed? #this saves us iterating once+1 when no execution took place return false if !self.executed? @step_states.each do |state| return true if state[1][:status]==:error && state[1][:strategy]==:fail_on_error return true if state[1][:status]==:warning && state[1][:strategy]==:fail_on_warning end @step_states.each{|state| return false if state[1][:status]==:not_executed || state[1][:status]==:running } return true end |
#error ⇒ Object
447 448 449 |
# File 'lib/patir/command.rb', line 447 def error return "" end |
#exec_time ⇒ Object
434 435 436 437 |
# File 'lib/patir/command.rb', line 434 def exec_time return @stop_time-@start_time if @stop_time return 0 end |
#executed? ⇒ Boolean
450 451 452 453 |
# File 'lib/patir/command.rb', line 450 def executed? return true unless @status==:not_executed return false end |
#name ⇒ Object
438 439 440 |
# File 'lib/patir/command.rb', line 438 def name return @sequence_name end |
#number ⇒ Object
441 442 443 |
# File 'lib/patir/command.rb', line 441 def number return @sequence_id end |
#output ⇒ Object
444 445 446 |
# File 'lib/patir/command.rb', line 444 def output return self.summary end |
#running? ⇒ Boolean
352 353 354 355 |
# File 'lib/patir/command.rb', line 352 def running? return true if :running==@status return false end |
#step=(step) ⇒ Object
Adds a step to the state. The step state is inferred from the Command instance __step__
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/patir/command.rb', line 385 def step=step @step_states[step.number]={:name=>step.name, :status=>step.status, :output=>step.output, :duration=>step.exec_time, :error=>step.error, :strategy=>step.strategy } #this way we don't have to compare all the step states we always get the worst last stable state #:not_executed<:success<:warning<:success unless @status==:running @previous_status=@status case step.status when :running @status=:running when :warning @status=:warning unless @status==:error @status=:error if @previous_status==:error when :error @status=:error when :success @status=:success unless @status==:error || @status==:warning @status=:warning if @previous_status==:warning @status=:error if @previous_status==:error when :not_executed @status=@previous_status end end#unless running end |
#step_state(number) ⇒ Object
A nil means there is no step with that number
380 381 382 383 |
# File 'lib/patir/command.rb', line 380 def step_state number s=@step_states[number] if @step_states[number] return s end |
#success? ⇒ Boolean
true is returned when all steps were succesfull.
357 358 359 360 |
# File 'lib/patir/command.rb', line 357 def success? return true if :success==@status return false end |
#summary ⇒ Object
produces a brief text summary for this status
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/patir/command.rb', line 415 def summary sum="" sum<<"#{@sequence_id}:" if @sequence_id sum<<"#{@sequence_name}. " unless @sequence_name.empty? sum<<"Status - #{@status}" if !@step_states.empty? && @status!=:not_executed sum<<". States #{@step_states.size}\nStep status summary:" sorter=Hash.new @step_states.each do |number,state| #sort them by number sorter[number]="\n\t#{number}:'#{state[:name]}' - #{state[:status]}" end 1.upto(sorter.size) {|i| sum<<sorter[i] if sorter[i]} end return sum end |
#to_s ⇒ Object
431 432 433 |
# File 'lib/patir/command.rb', line 431 def to_s "'#{sequence_id}':'#{@sequence_name}' on '#{@sequence_runner}' started at #{@start_time}.#{@step_states.size} steps" end |