Class: Lavin::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/lavin/step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, user:, repeat: 1, &block) ⇒ Step

Returns a new instance of Step.



9
10
11
12
13
14
# File 'lib/lavin/step.rb', line 9

def initialize(name:, user:, repeat: 1, &block)
  @name = name
  @user = user
  @repeat = repeat
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



7
8
9
# File 'lib/lavin/step.rb', line 7

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/lavin/step.rb', line 7

def name
  @name
end

#repeatObject (readonly)

Returns the value of attribute repeat.



7
8
9
# File 'lib/lavin/step.rb', line 7

def repeat
  @repeat
end

#userObject (readonly)

Returns the value of attribute user.



7
8
9
# File 'lib/lavin/step.rb', line 7

def user
  @user
end

Instance Method Details

#call(context:) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lavin/step.rb', line 23

def call(context:)
  context.instance_exec(&block)
  Statistics.register_step(user: user.name, step_name: name)
rescue SuccessfulStep, SuccessfulUser => error
  Statistics.register_step(user: user.name, step_name: name)
  throw :stop_user if error.is_a? SuccessfulUser
rescue IrrecoverableError => error
  Statistics.register_step(user: user.name, step_name: name, failure: error.message)
  throw :stop_user
rescue => error
  puts "Exception in #{user.name}.#{name} - #{error.class}: #{error.message}"
  Statistics.register_step(user: user.name, step_name: name, failure: error.message)
end

#run(context: nil) ⇒ Object



16
17
18
19
20
21
# File 'lib/lavin/step.rb', line 16

def run(context: nil)
  repeat.times do
    call(context:)
    Runner.yield
  end
end