Module: Crossbeam::Callbacks::ClassMethods
- Defined in:
- lib/crossbeam/callbacks.rb
Overview
Methods to load in the service object as class methods
Instance Method Summary collapse
-
#after(*callbacks) { ... } ⇒ Void
Add callback
aftermethod or block. -
#after_callbacks ⇒ Array
Create a list of
aftercallback methods and/or blocks. -
#before(*callbacks) { ... } ⇒ Void
Add callback
beforemethod or block. -
#before_callbacks ⇒ Array
Create a list of
beforecallback methods and/or blocks. -
#run_after_callbacks ⇒ Void
Call and run all callbacks after
#callhas ran. -
#run_before_callbacks ⇒ Void
Call all callbacks before
#callis referenced (methods, blocks, etc.). -
#run_callbacks(callbacks) ⇒ Void
Loopthrough and run all the classes listed callback methods.
Instance Method Details
#after(*callbacks) { ... } ⇒ Void
Add callback after method or block
37 38 39 40 |
# File 'lib/crossbeam/callbacks.rb', line 37 def after(*callbacks, &block) callbacks << block if block callbacks.each { |callback| after_callbacks << callback } end |
#after_callbacks ⇒ Array
Create a list of after callback methods and/or blocks
60 61 62 |
# File 'lib/crossbeam/callbacks.rb', line 60 def after_callbacks @after_callbacks ||= [] end |
#before(*callbacks) { ... } ⇒ Void
Add callback before method or block
27 28 29 30 |
# File 'lib/crossbeam/callbacks.rb', line 27 def before(*callbacks, &block) callbacks << block if block callbacks.each { |callback| before_callbacks << callback } end |
#before_callbacks ⇒ Array
Create a list of before callback methods and/or blocks
67 68 69 |
# File 'lib/crossbeam/callbacks.rb', line 67 def before_callbacks @before_callbacks ||= [] end |
#run_after_callbacks ⇒ Void
Call and run all callbacks after #call has ran
53 54 55 |
# File 'lib/crossbeam/callbacks.rb', line 53 def run_after_callbacks run_callbacks(after_callbacks) end |
#run_before_callbacks ⇒ Void
Call all callbacks before #call is referenced (methods, blocks, etc.)
45 46 47 48 |
# File 'lib/crossbeam/callbacks.rb', line 45 def run_before_callbacks # run_callbacks(self.class.before_callbacks) run_callbacks(before_callbacks) end |
#run_callbacks(callbacks) ⇒ Void
Loopthrough and run all the classes listed callback methods
75 76 77 |
# File 'lib/crossbeam/callbacks.rb', line 75 def run_callbacks(callbacks) callbacks.each { |callback| run_callback(callback) } end |