Class: Graphiti::Util::TransactionHooksRecorder

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti/util/transaction_hooks_recorder.rb

Class Method Summary collapse

Class Method Details

.add(prc, lifecycle_event) ⇒ Object

Because hooks will be added from the outer edges of the graph, working inwards



50
51
52
# File 'lib/graphiti/util/transaction_hooks_recorder.rb', line 50

def add(prc, lifecycle_event)
  hook_set(lifecycle_event).unshift(prc)
end

.recordObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/graphiti/util/transaction_hooks_recorder.rb', line 25

def record
  reset_hooks

  begin
    result = yield
    run(:before_commit)

    unless result.is_a?(::Hash)
      result = {result: result}
    end

    result.tap do |r|
      r[:after_commit_hooks] = hook_set(:after_commit)
    end
  ensure
    reset_hooks
  end
end

.run(lifecycle_event) ⇒ Object



54
55
56
# File 'lib/graphiti/util/transaction_hooks_recorder.rb', line 54

def run(lifecycle_event)
  _hooks[lifecycle_event].each { |h| h.call }
end

.run_graph_persist_hooksObject



44
45
46
# File 'lib/graphiti/util/transaction_hooks_recorder.rb', line 44

def run_graph_persist_hooks
  run(:after_graph_persist)
end