class Handlers::BeforeSaveHooks
Public Instance Methods
handle()
click to toggle source
# File lib/handlers/hooks.rb, line 5 def handle handle_hooks('before_save') end
handle_block(block)
click to toggle source
# File lib/handlers/hooks.rb, line 21 def handle_block(block) @klass.instance_eval(&block) end
handle_hooks(hook_name)
click to toggle source
# File lib/handlers/hooks.rb, line 9 def handle_hooks(hook_name) (upper("@@#{hook_name}") || []).each do |method_or_block| handle_single(method_or_block) end end
handle_method(method)
click to toggle source
# File lib/handlers/hooks.rb, line 25 def handle_method(method) raise_error("could not find hook method named #{method}") unless @klass.respond_to?(method) @klass.send(method) end
handle_single(method_or_block)
click to toggle source
# File lib/handlers/hooks.rb, line 15 def handle_single(method_or_block) raise_error('a hook seems to be nil') if method_or_block.nil? method_or_block.respond_to?(:call) ? handle_block(method_or_block) : handle_method(method_or_block) end