Module: Foobara::Entity::Concerns::Callbacks
- Includes:
- Concern
- Included in:
- Foobara::Entity
- Defined in:
- foobara-0.0.110/projects/entity/src/concerns/callbacks.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#callback_registry ⇒ Object
owner helps with determining the relevant object when running class-registered state transition callbacks.
Class Method Summary collapse
Instance Method Summary collapse
-
#fire(action, data = {}) ⇒ Object
TODO: support passing multiple actions here.
- #initialize ⇒ Object
- #without_callbacks ⇒ Object
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Instance Attribute Details
#callback_registry ⇒ Object
owner helps with determining the relevant object when running class-registered state transition callbacks
14 15 16 |
# File 'foobara-0.0.110/projects/entity/src/concerns/callbacks.rb', line 14 def callback_registry @callback_registry end |
Class Method Details
.reset_all ⇒ Object
8 9 10 |
# File 'foobara-0.0.110/projects/entity/src/concerns/callbacks.rb', line 8 def reset_all Entity.instance_variable_set("@class_callback_registry", nil) end |
Instance Method Details
#fire(action, data = {}) ⇒ Object
TODO: support passing multiple actions here
22 23 24 |
# File 'foobara-0.0.110/projects/entity/src/concerns/callbacks.rb', line 22 def fire(action, data = {}) callback_registry.runner(action).callback_data(data.merge(record: self, action:)).run end |
#initialize ⇒ Object
16 17 18 19 |
# File 'foobara-0.0.110/projects/entity/src/concerns/callbacks.rb', line 16 def initialize(...) self.callback_registry = Callback::Registry::ChainedMultipleAction.new(self.class.class_callback_registry) super end |
#without_callbacks ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'foobara-0.0.110/projects/entity/src/concerns/callbacks.rb', line 26 def without_callbacks old_callbacks_enabled = @callbacks_disabled begin @callbacks_disabled = true yield ensure @callbacks_disabled = old_callbacks_enabled end end |