Module: MR::AfterCommit::RecordProcsMethods

Defined in:
lib/mr/after_commit/record_procs_methods.rb

Constant Summary collapse

VALID_CALLBACK_TYPES =
[
  :create,
  :update,
  :save,
  :destroy
].freeze
DEFAULT_CALLBACK_TYPE =
:save.freeze

Instance Method Summary collapse

Instance Method Details

#add_after_commit_proc(callback_type = nil, &block) ⇒ Object



25
26
27
28
# File 'lib/mr/after_commit/record_procs_methods.rb', line 25

def add_after_commit_proc(callback_type = nil, &block)
  callback_type ||= DEFAULT_CALLBACK_TYPE
  mr_after_commit_procs_hash[callback_type.to_sym] << block
end

#after_commit_procs(*keys) ⇒ Object

these methods are used by the ‘Record` and `FakeRecord` mixins



17
18
19
20
21
22
23
# File 'lib/mr/after_commit/record_procs_methods.rb', line 17

def after_commit_procs(*keys)
  if keys.empty?
    mr_after_commit_procs_hash.values.flatten
  else
    keys.map{ |k| mr_after_commit_procs_hash[k.to_sym] }.flatten
  end
end

#called_after_commit_procs(*keys) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/mr/after_commit/record_procs_methods.rb', line 43

def called_after_commit_procs(*keys)
  if keys.empty?
    mr_after_commit_called_procs_hash.values.flatten
  else
    keys.map{ |k| mr_after_commit_called_procs_hash[k.to_sym] }.flatten
  end
end

#clear_after_commit_procs(*keys) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/mr/after_commit/record_procs_methods.rb', line 35

def clear_after_commit_procs(*keys)
  if keys.empty?
    mr_after_commit_procs_hash.clear
  else
    keys.map{ |k| mr_after_commit_procs_hash.delete(k.to_sym) }
  end
end

#prepend_after_commit_proc(callback_type = nil, &block) ⇒ Object



30
31
32
33
# File 'lib/mr/after_commit/record_procs_methods.rb', line 30

def prepend_after_commit_proc(callback_type = nil, &block)
  callback_type ||= DEFAULT_CALLBACK_TYPE
  mr_after_commit_procs_hash[callback_type.to_sym].unshift(block)
end