Class: Burden::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/burden/wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, block) ⇒ Wrapper

Returns a new instance of Wrapper.



5
6
7
8
9
10
# File 'lib/burden/wrapper.rb', line 5

def initialize(name, block)
  @name = name
  @block = block
  @success = true
  @timestamp = Time.now.utc
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



3
4
5
# File 'lib/burden/wrapper.rb', line 3

def block
  @block
end

#exceptionObject (readonly)

Returns the value of attribute exception.



3
4
5
# File 'lib/burden/wrapper.rb', line 3

def exception
  @exception
end

#execution_timeObject (readonly)

Returns the value of attribute execution_time.



3
4
5
# File 'lib/burden/wrapper.rb', line 3

def execution_time
  @execution_time
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/burden/wrapper.rb', line 3

def name
  @name
end

#successObject (readonly)

Returns the value of attribute success.



3
4
5
# File 'lib/burden/wrapper.rb', line 3

def success
  @success
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



3
4
5
# File 'lib/burden/wrapper.rb', line 3

def timestamp
  @timestamp
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/burden/wrapper.rb', line 12

def execute
  return block.call if ignored?

  result = measure_time do
    intercept_exceptions do
      block.call
    end
  end
  save_statistics

  unless success
    Burden.config.trigger_failure_callback(name, execution_time, timestamp)
    raise(exception)
  end

  Burden.config.trigger_success_callback(name, execution_time, timestamp)
  result
end