Module: Rooftop::HookCalls::ClassMethods
- Defined in:
- lib/rooftop/hook_calls.rb
Instance Method Summary collapse
-
#add_to_hook(hook, block) ⇒ Object
Add something to the list of hook calls, for a particular hook.
-
#setup_hooks! ⇒ Object
A method to call the hooks.
Instance Method Details
#add_to_hook(hook, block) ⇒ Object
Add something to the list of hook calls, for a particular hook. This is called in other mixins where something is being added to a hook (probably :after_find). For example Rooftop::FieldAliases and Rooftop::FieldCoercions
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rooftop/hook_calls.rb', line 16 def add_to_hook(hook, block) # get existing hook calls hook_calls = instance_variable_get(:"@hook_calls") # add new one for the appropriate hook if hook_calls[hook].is_a?(Array) hook_calls[hook] << block else hook_calls[hook] = [block] end instance_variable_set(:"@hook_calls",hook_calls) end |
#setup_hooks! ⇒ Object
A method to call the hooks. This iterates over each of the types of hook (:after_find, :before_save etc, identified here: github.com/remiprev/her#callbacks) and sets up the actual hook. All this is worth it to control order.
31 32 33 34 35 36 37 |
# File 'lib/rooftop/hook_calls.rb', line 31 def setup_hooks! instance_variable_get(:"@hook_calls").each do |type, calls| calls.each do |call| self.send(type, call) end end end |