module ServiceOperation::Hooks::ClassMethods
Hook Methods
Public Instance Methods
after(*hooks, &block)
click to toggle source
# File lib/service_operation/hooks.rb, line 29 def after(*hooks, &block) add_hooks(:after, hooks, block, :unshift) end
after_hooks()
click to toggle source
@return [Array<Symbol, Proc>]
# File lib/service_operation/hooks.rb, line 44 def after_hooks @after_hooks ||= initial_hooks(:after_hooks) end
around(*hooks, &block)
click to toggle source
@example
around do |op| result = nil ms = Benchmark.ms { result = op.call } puts "#{self.class.name} took #{ms}" result end
# File lib/service_operation/hooks.rb, line 21 def around(*hooks, &block) add_hooks(:around, hooks, block) end
around_hooks()
click to toggle source
@return [Array<Symbol, Proc>]
# File lib/service_operation/hooks.rb, line 34 def around_hooks @around_hooks ||= initial_hooks(:around_hooks) end
before(*hooks, &block)
click to toggle source
# File lib/service_operation/hooks.rb, line 25 def before(*hooks, &block) add_hooks(:before, hooks, block) end
before_hooks()
click to toggle source
@return [Array<Symbol, Proc>]
# File lib/service_operation/hooks.rb, line 39 def before_hooks @before_hooks ||= initial_hooks(:before_hooks) end
Private Instance Methods
add_hooks(name, hooks, block, method = :push)
click to toggle source
rubocop:enable Style/SafeNavigation
# File lib/service_operation/hooks.rb, line 56 def add_hooks(name, hooks, block, method = :push) hooks << block if block hooks.each { |hook| send("#{name}_hooks").send(method, hook) } end
initial_hooks(name)
click to toggle source
rubocop:disable Style/SafeNavigation
# File lib/service_operation/hooks.rb, line 51 def initial_hooks(name) superclass && superclass.respond_to?(name) ? superclass.send(name).dup : [] end