Module: ServiceOperation::Hooks::ClassMethods

Defined in:
lib/service_operation/hooks.rb

Overview

Hook Methods

Instance Method Summary collapse

Instance Method Details

#after(*hooks, &block) ⇒ Object



29
30
31
# File 'lib/service_operation/hooks.rb', line 29

def after(*hooks, &block)
  add_hooks(:after, hooks, block, :unshift)
end

#after_hooksArray<Symbol, Proc>

Returns:

  • (Array<Symbol, Proc>)


44
45
46
# File 'lib/service_operation/hooks.rb', line 44

def after_hooks
  @after_hooks ||= initial_hooks(:after_hooks)
end

#around(*hooks, &block) ⇒ Object

Examples:

around do |op|
  result = nil
  ms = Benchmark.ms { result = op.call }
  puts "#{self.class.name} took #{ms}"
  result
end


21
22
23
# File 'lib/service_operation/hooks.rb', line 21

def around(*hooks, &block)
  add_hooks(:around, hooks, block)
end

#around_hooksArray<Symbol, Proc>

Returns:

  • (Array<Symbol, Proc>)


34
35
36
# File 'lib/service_operation/hooks.rb', line 34

def around_hooks
  @around_hooks ||= initial_hooks(:around_hooks)
end

#before(*hooks, &block) ⇒ Object



25
26
27
# File 'lib/service_operation/hooks.rb', line 25

def before(*hooks, &block)
  add_hooks(:before, hooks, block)
end

#before_hooksArray<Symbol, Proc>

Returns:

  • (Array<Symbol, Proc>)


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

def before_hooks
  @before_hooks ||= initial_hooks(:before_hooks)
end