Class: Stormtroopers::Trooper

Inherits:
Object
  • Object
show all
Defined in:
lib/stormtroopers/trooper.rb

Direct Known Subclasses

DelayedJobTrooper, DummyTrooper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters = {}, &block) ⇒ Trooper

Returns a new instance of Trooper.



5
6
7
8
# File 'lib/stormtroopers/trooper.rb', line 5

def initialize(parameters = {}, &block)
  @parameters = parameters
  @task = block
end

Instance Attribute Details

#parametersObject (readonly)

Returns the value of attribute parameters.



3
4
5
# File 'lib/stormtroopers/trooper.rb', line 3

def parameters
  @parameters
end

#taskObject (readonly)

Returns the value of attribute task.



3
4
5
# File 'lib/stormtroopers/trooper.rb', line 3

def task
  @task
end

Instance Method Details

#after_runObject



14
15
16
# File 'lib/stormtroopers/trooper.rb', line 14

def after_run
  # Empty hook for overriding
end

#before_runObject



10
11
12
# File 'lib/stormtroopers/trooper.rb', line 10

def before_run
  # Empty hook for overriding
end

#exception(exception) ⇒ Object



18
19
20
21
# File 'lib/stormtroopers/trooper.rb', line 18

def exception(exception)
  # Hook for to override handling exceptions
  raise exception
end

#loggerObject



31
32
33
# File 'lib/stormtroopers/trooper.rb', line 31

def logger
  Manager.logger
end

#runObject



23
24
25
26
27
28
29
# File 'lib/stormtroopers/trooper.rb', line 23

def run
  before_run
  task.call
  after_run
rescue => e
  exception(e)
end