Class: CleanActions::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/clean_actions/action.rb

Direct Known Subclasses

Base

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.before_actions(&block) ⇒ Object



8
9
10
# File 'lib/clean_actions/action.rb', line 8

def before_actions(&block)
  before_actions_blocks << block
end

.before_actions_blocksObject



12
13
14
# File 'lib/clean_actions/action.rb', line 12

def before_actions_blocks
  @before_actions_blocks ||= []
end

.call(with_savepoint: false, **kwargs) ⇒ Object



4
5
6
# File 'lib/clean_actions/action.rb', line 4

def call(with_savepoint: false, **kwargs)
  new(**kwargs).call(with_savepoint: with_savepoint)
end

.isolation_levelObject



22
23
24
# File 'lib/clean_actions/action.rb', line 22

def isolation_level
  @isolation_level ||= CleanActions.config.isolation_level
end

.with_isolation_level(isolation_level) ⇒ Object



16
17
18
19
20
# File 'lib/clean_actions/action.rb', line 16

def with_isolation_level(isolation_level)
  IsolationLevelValidator.validate(isolation_level)

  @isolation_level = isolation_level
end

Instance Method Details

#after_commitObject



50
51
# File 'lib/clean_actions/action.rb', line 50

def after_commit
end

#call(with_savepoint: false) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/clean_actions/action.rb', line 27

def call(with_savepoint: false)
  if TransactionRunner.action_calls_restricted_by
    ErrorReporter.report("calling action #{self.class.name} is resticted inside ##{TransactionRunner.action_calls_restricted_by}")
  end

  TransactionRunner.restrict_action_calls_by(:before_transaction) { perform_before_transaction }

  TransactionRunner.new(self).run(with_savepoint: with_savepoint) do
    TransactionRunner.restrict_action_calls_by(:before_actions) do
      self.class.before_actions_blocks.each { |b| instance_eval(&b) }
    end

    perform_actions
  end
end

#ensureObject



53
54
# File 'lib/clean_actions/action.rb', line 53

def ensure
end

#fail!(reason) ⇒ Object

Raises:



43
44
45
# File 'lib/clean_actions/action.rb', line 43

def fail!(reason)
  raise ActionFailure.new(reason)
end

#perform_actionsObject



47
48
# File 'lib/clean_actions/action.rb', line 47

def perform_actions
end

#rollbackObject



56
57
# File 'lib/clean_actions/action.rb', line 56

def rollback
end