class Graphiti::Util::TransactionHooksRecorder
Public Class Methods
add(prc, lifecycle_event)
click to toggle source
Because hooks will be added from the outer edges of the graph, working inwards
# File lib/graphiti/util/transaction_hooks_recorder.rb, line 50 def add(prc, lifecycle_event) hook_set(lifecycle_event).unshift(prc) end
record() { || ... }
click to toggle source
# 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)
click to toggle source
# 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_hooks()
click to toggle source
# File lib/graphiti/util/transaction_hooks_recorder.rb, line 44 def run_graph_persist_hooks run(:after_graph_persist) end
Private Class Methods
_hooks()
click to toggle source
# File lib/graphiti/util/transaction_hooks_recorder.rb, line 60 def _hooks Thread.current[:_graphiti_hooks] end
hook_set(lifecycle_event)
click to toggle source
# File lib/graphiti/util/transaction_hooks_recorder.rb, line 72 def hook_set(lifecycle_event) _hooks[lifecycle_event] end
reset_hooks()
click to toggle source
# File lib/graphiti/util/transaction_hooks_recorder.rb, line 64 def reset_hooks Thread.current[:_graphiti_hooks] = { after_graph_persist: [], before_commit: [], after_commit: [] } end