Class: TableSync::Config::CallbackRegistry
- Inherits:
-
Object
- Object
- TableSync::Config::CallbackRegistry
- Defined in:
- lib/table_sync/config/callback_registry.rb
Constant Summary collapse
- CALLBACK_KINDS =
%i[after_commit before_commit].freeze
- EVENTS =
%i[create update destroy].freeze
- InvalidCallbackKindError =
Class.new(ArgumentError)
- InvalidEventError =
Class.new(ArgumentError)
Instance Method Summary collapse
- #get_callbacks(kind:, event:) ⇒ Object
-
#initialize ⇒ CallbackRegistry
constructor
A new instance of CallbackRegistry.
- #register_callback(callback, kind:, event:) ⇒ Object
Constructor Details
#initialize ⇒ CallbackRegistry
Returns a new instance of CallbackRegistry.
10 11 12 |
# File 'lib/table_sync/config/callback_registry.rb', line 10 def initialize @callbacks = CALLBACK_KINDS.map { |event| [event, make_event_hash] }.to_h end |
Instance Method Details
#get_callbacks(kind:, event:) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/table_sync/config/callback_registry.rb', line 21 def get_callbacks(kind:, event:) validate_callback_kind!(kind) validate_event!(event) callbacks.fetch(kind).fetch(event, []) end |
#register_callback(callback, kind:, event:) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/table_sync/config/callback_registry.rb', line 14 def register_callback(callback, kind:, event:) validate_callback_kind!(kind) validate_event!(event) callbacks.fetch(kind)[event] << callback end |