Module: Hook::ClassMethods

Defined in:
lib/hook.rb

Instance Method Summary collapse

Instance Method Details

#after_hooksObject



63
64
65
# File 'lib/hook.rb', line 63

def after_hooks
  @after_hooks ||= scoped_callbacks
end

#around_hooksObject



67
68
69
# File 'lib/hook.rb', line 67

def around_hooks
  @around_hooks ||= scoped_callbacks
end

#before_hooksObject



59
60
61
# File 'lib/hook.rb', line 59

def before_hooks
  @before_hooks ||= scoped_callbacks
end

#hookObject



31
32
33
# File 'lib/hook.rb', line 31

def hook
  ::Hook::HookDecorator
end

#hook_after(method, &block) ⇒ Object



39
40
41
# File 'lib/hook.rb', line 39

def hook_after method, &block 
  after_hooks[method.to_s] << block
end

#hook_around(method, &block) ⇒ Object



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

def hook_around method, &block 
  around_hooks[method.to_s] << block
end

#hook_before(method, &block) ⇒ Object



35
36
37
# File 'lib/hook.rb', line 35

def hook_before method, &block 
  before_hooks[method.to_s] << block
end

#remove_all_callbacks!Object



53
54
55
56
57
# File 'lib/hook.rb', line 53

def remove_all_callbacks!
  @before_hooks = nil
  @after_hooks = nil
  @around_hooks = nil
end

#remove_callbacks!(method) ⇒ Object



47
48
49
50
51
# File 'lib/hook.rb', line 47

def remove_callbacks! method
  [before_hooks, after_hooks, around_hooks].each do |hooks|
    hooks[method.to_s] = []
  end
end