Module: Her::Model::Hooks
- Defined in:
- lib/her/model/hooks.rb
Instance Method Summary collapse
- #after_create(method = nil, &block) ⇒ Object
- #after_destroy(method = nil, &block) ⇒ Object
- #after_save(method = nil, &block) ⇒ Object
- #after_update(method = nil, &block) ⇒ Object
- #before_create(method = nil, &block) ⇒ Object
- #before_destroy(method = nil, &block) ⇒ Object
-
#before_save(method = nil, &block) ⇒ Object
}}}.
- #before_update(method = nil, &block) ⇒ Object
-
#hooks ⇒ Object
Return hooks.
- #perform_hook(record, time, name) ⇒ Object
- #set_hook(time, name, action) ⇒ Object
Instance Method Details
#after_create(method = nil, &block) ⇒ Object
35 |
# File 'lib/her/model/hooks.rb', line 35 def after_create(method=nil, &block); set_hook(:after, :create, method || block); end |
#after_destroy(method = nil, &block) ⇒ Object
37 |
# File 'lib/her/model/hooks.rb', line 37 def after_destroy(method=nil, &block); set_hook(:after, :destroy, method || block); end |
#after_save(method = nil, &block) ⇒ Object
34 |
# File 'lib/her/model/hooks.rb', line 34 def after_save(method=nil, &block); set_hook(:after, :save, method || block); end |
#after_update(method = nil, &block) ⇒ Object
36 |
# File 'lib/her/model/hooks.rb', line 36 def after_update(method=nil, &block); set_hook(:after, :update, method || block); end |
#before_create(method = nil, &block) ⇒ Object
30 |
# File 'lib/her/model/hooks.rb', line 30 def before_create(method=nil, &block); set_hook(:before, :create, method || block); end |
#before_destroy(method = nil, &block) ⇒ Object
32 |
# File 'lib/her/model/hooks.rb', line 32 def before_destroy(method=nil, &block); set_hook(:before, :destroy, method || block); end |
#before_save(method = nil, &block) ⇒ Object
}}}
29 |
# File 'lib/her/model/hooks.rb', line 29 def before_save(method=nil, &block); set_hook(:before, :save, method || block); end |
#before_update(method = nil, &block) ⇒ Object
31 |
# File 'lib/her/model/hooks.rb', line 31 def before_update(method=nil, &block); set_hook(:before, :update, method || block); end |
#hooks ⇒ Object
Return hooks
6 7 8 |
# File 'lib/her/model/hooks.rb', line 6 def hooks # {{{ @her_hooks end |
#perform_hook(record, time, name) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/her/model/hooks.rb', line 17 def perform_hook(record, time, name) # {{{ @her_hooks ||= {} hooks = @her_hooks["#{time}_#{name}".to_sym] || [] hooks.each do |hook| if hook.is_a? Symbol record.send(hook) else hook.call(record) end end end |
#set_hook(time, name, action) ⇒ Object
11 12 13 14 |
# File 'lib/her/model/hooks.rb', line 11 def set_hook(time, name, action) # {{{ @her_hooks ||= {} (@her_hooks["#{time}_#{name}".to_sym] ||= []) << action end |