module ActiveService::Hooks::ClassMethods
Public Instance Methods
add_hook(type, action, *args, &block)
click to toggle source
# File lib/active_service/hooks.rb, line 23 def add_hook(type, action, *args, &block) options = extract_options! *args if args.first.is_a? Symbol block = lambda { |*ops| send(args.first, *ops) } end send("#{type}_hooks",action).push(block) end
after(action, *args, &block)
click to toggle source
# File lib/active_service/hooks.rb, line 39 def after(action, *args, &block) add_hook(:after, action, *args, &block) end
around(action, *args, &block)
click to toggle source
# File lib/active_service/hooks.rb, line 43 def around(action, *args, &block) add_hook(:around, action, *args, &block) end
before(action, *args, &block)
click to toggle source
# File lib/active_service/hooks.rb, line 35 def before(action, *args, &block) add_hook(:before, action, *args, &block) end
extract_options!(*args)
click to toggle source
# File lib/active_service/hooks.rb, line 65 def extract_options!(*args) args.last.is_a?(::Hash) ? args.pop : {} end
run_after_hooks(obj, action)
click to toggle source
# File lib/active_service/hooks.rb, line 51 def run_after_hooks(obj, action) after_hooks(action).each { |h| run_hook(h, obj, action) } end
run_around_hooks(obj, action, &block)
click to toggle source
# File lib/active_service/hooks.rb, line 55 def run_around_hooks(obj, action, &block) around_hooks(action).inject(block) { |chain, hook| proc { run_hook(hook, obj, chain) } }.call end
run_before_hooks(obj, action)
click to toggle source
# File lib/active_service/hooks.rb, line 47 def run_before_hooks(obj, action) before_hooks(action).each { |h| run_hook(h, obj, action) } end
run_hook(hook, obj, *args)
click to toggle source
# File lib/active_service/hooks.rb, line 61 def run_hook(hook, obj, *args) obj.instance_exec(*args, &hook) end