We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
We should support ActiveSupport::Callbacks. Tentatively, I want to say we should provide them for:
initialize
validate
execute
run
That way you could have code like this:
class Interaction < ActiveInteraction::Base set_callback :run, :before, -> (o) { ... } set_callback :run, :after, -> (o) { ... } set_callback :run, :around, -> (o, &b) { ... } end
The text was updated successfully, but these errors were encountered:
I wrote an MVP for this feature:
Class.new(ActiveInteraction::Base) do include ActiveSupport::Callbacks define_callbacks :initialize alias_method :_initialize, :initialize def initialize(*args, &block) run_callbacks(:initialize) { _initialize(*args, &block) } end set_callback :initialize, :before, -> (_) { puts 'before' } set_callback :initialize, :after, -> (_) { puts 'after' } set_callback :initialize, :around, -> (_, &b) { puts '(', b.call, ')' } def execute; end end.run
That returns:
before ( {} ) after
Sorry, something went wrong.
Turns out we already support callbacks! ActiveModel gives use :validate callbacks for free.
:validate
class Interaction < ActiveInteraction::Base set_callback :validate, :before, lambda { |_| puts 'before' } set_callback :validate, :after, lambda { |_| puts 'after' } set_callback :validate, :around, lambda { |_, &block| puts 'around' block.call puts 'around' } def execute puts 'execute' end end Interaction.run
before around around after execute
Fix #115; add execute callback
26a8562
tfausak
No branches or pull requests
We should support ActiveSupport::Callbacks. Tentatively, I want to say we should provide them for:
initialize
validate
execute
(orrun
)That way you could have code like this:
The text was updated successfully, but these errors were encountered: