Module: Falqon::Hooks::ClassMethods

Extended by:
T::Sig
Includes:
Kernel
Defined in:
lib/falqon/concerns/hooks.rb

Instance Method Summary collapse

Instance Method Details

#after(event, method_sym = nil, &block) ⇒ Object



94
95
96
97
98
# File 'lib/falqon/concerns/hooks.rb', line 94

def after(event, method_sym = nil, &block)
  block ||= proc { send(method_sym) } if method_sym

  T.must(T.must(hooks[event])[:after]) << block if block
end

#before(event, method_sym = nil, &block) ⇒ Object



80
81
82
83
84
# File 'lib/falqon/concerns/hooks.rb', line 80

def before(event, method_sym = nil, &block)
  block ||= proc { send(method_sym) } if method_sym

  T.must(T.must(hooks[event])[:before]) << block if block
end

#hooksObject



68
69
70
# File 'lib/falqon/concerns/hooks.rb', line 68

def hooks
  @hooks ||= Hash.new { |h, k| h[k] = { before: [], after: [] } }
end