Class: Transactor::Performance

Inherits:
Object
  • Object
show all
Defined in:
lib/transactor/performance.rb

Direct Known Subclasses

Improv::Performance

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actorObject (readonly)

Returns the value of attribute actor.



3
4
5
# File 'lib/transactor/performance.rb', line 3

def actor
  @actor
end

#resultObject (readonly)

Returns the value of attribute result.



3
4
5
# File 'lib/transactor/performance.rb', line 3

def result
  @result
end

Class Method Details

.perform(actor, *args, &block) ⇒ Object



5
6
7
# File 'lib/transactor/performance.rb', line 5

def self.perform(actor, *args, &block)
  new(actor, *args).perform(&block)
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/transactor/performance.rb', line 42

def failed?
  started? && rolled_back?
end

#perform(&block) ⇒ Object



9
10
11
12
13
14
# File 'lib/transactor/performance.rb', line 9

def perform(&block)
  @started = true
  @result = actor.perform(&block)
  @performed = true
  self
end

#performed?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/transactor/performance.rb', line 26

def performed?
  !!@performed
end

#performing?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/transactor/performance.rb', line 34

def performing?
  started? && !performed?
end

#rollback(&block) ⇒ Object



16
17
18
19
20
# File 'lib/transactor/performance.rb', line 16

def rollback(&block)
  actor.rollback(&block)
  @rolled_back = true
  self
end

#rollback_on_failure?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/transactor/performance.rb', line 46

def rollback_on_failure?
  actor.rollback_on_failure?
end

#rolled_back?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/transactor/performance.rb', line 30

def rolled_back?
  !!@rolled_back
end

#started?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/transactor/performance.rb', line 22

def started?
  !!@started
end

#stateObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/transactor/performance.rb', line 50

def state
  if failed?
    :failed
  elsif successful?
    :successful
  elsif performing?
    :performing
  elsif !started?
    :not_started
  else
    :unknown
  end
end

#successful?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/transactor/performance.rb', line 38

def successful?
  performed? && !rolled_back?
end

#to_sObject



64
65
66
# File 'lib/transactor/performance.rb', line 64

def to_s
  "#{actor.to_s} #{state}"
end