Module: Datamappify::Repository::QueryMethod::Callbacks
- Defined in:
- lib/datamappify/repository/query_method/callbacks.rb
Class Method Summary collapse
Instance Method Summary collapse
- #hook_for(type, filter) ⇒ String private
- #run_callbacks(entity, *types) { ... } ⇒ void
- #run_hooks(types, filter, entity) ⇒ Boolean private
Class Method Details
.included(klass) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/datamappify/repository/query_method/callbacks.rb', line 27 def self.included(klass) klass.class_eval do include Hooks define_hooks :before_create, :after_create, :before_update, :after_update, :before_save, :after_save, :before_destroy, :after_destroy end end |
Instance Method Details
#hook_for(type, filter) ⇒ String (private)
77 78 79 |
# File 'lib/datamappify/repository/query_method/callbacks.rb', line 77 def hook_for(type, filter) "#{filter}_#{type}" end |
#run_callbacks(entity, *types) { ... } ⇒ void
This method returns an undefined value.
46 47 48 49 50 51 |
# File 'lib/datamappify/repository/query_method/callbacks.rb', line 46 def run_callbacks(entity, *types, &block) run_hooks(types, :before, entity) && (yield_value = block.call) && run_hooks(types.reverse, :after, entity) && yield_value end |
#run_hooks(types, filter, entity) ⇒ Boolean (private)
64 65 66 67 68 |
# File 'lib/datamappify/repository/query_method/callbacks.rb', line 64 def run_hooks(types, filter, entity) types.take_while do |type| run_hook(hook_for(type, filter), entity) end.length == types.length end |