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) ⇒ Symbol private
- #run_callbacks(entity, *types) { ... } ⇒ void
- #run_hooks(types, filter, entity) ⇒ Boolean private
Class Method Details
.included(klass) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/datamappify/repository/query_method/callbacks.rb', line 7 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, :halts_on_falsey => true end end |
Instance Method Details
#hook_for(type, filter) ⇒ Symbol (private)
58 59 60 |
# File 'lib/datamappify/repository/query_method/callbacks.rb', line 58 def hook_for(type, filter) :"#{filter}_#{type}" end |
#run_callbacks(entity, *types) { ... } ⇒ void
This method returns an undefined value.
27 28 29 30 31 32 |
# File 'lib/datamappify/repository/query_method/callbacks.rb', line 27 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)
45 46 47 48 49 |
# File 'lib/datamappify/repository/query_method/callbacks.rb', line 45 def run_hooks(types, filter, entity) types.take_while do |type| run_hook(hook_for(type, filter), entity).not_halted? end.length == types.length end |