Skip to content

Commit

Permalink
Add NamedCallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
antulik committed Jul 11, 2024
1 parent 8244b59 commit a1a5cb3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/active_interaction/extras.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Jobs
autoload(:FilterAlias, "active_interaction/extras/filter_alias")
autoload(:Halt, "active_interaction/extras/halt")
autoload(:ModelFields, "active_interaction/extras/model_fields")
autoload(:NamedCallbacks, "active_interaction/extras/named_callbacks")
autoload(:NestedAttributes, "active_interaction/extras/nested_attributes")
autoload(:RunCallback, "active_interaction/extras/run_callback")
autoload(:StrongParams, "active_interaction/extras/strong_params")
Expand Down
1 change: 1 addition & 0 deletions lib/active_interaction/extras/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module ActiveInteraction::Extras::All
extend ActiveSupport::Concern

# order dependant, include first so around callback includes other modules
include ActiveInteraction::Extras::NamedCallbacks
include ActiveInteraction::Extras::Transaction

include ActiveInteraction::Extras::FilterAlias
Expand Down
43 changes: 43 additions & 0 deletions lib/active_interaction/extras/named_callbacks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module ActiveInteraction::Extras::NamedCallbacks
extend ActiveSupport::Concern

class_methods do
def before_filter(...)
set_callback(:filter, :before, ...)
end

def after_filter(...)
set_callback(:filter, :after, ...)
end

def around_filter(...)
set_callback(:filter, :around, ...)
end


def before_validate(...)
set_callback(:validate, :before, ...)
end

def after_validate(...)
set_callback(:validate, :after, ...)
end

def around_validate(...)
set_callback(:validate, :around, ...)
end


def before_execute(...)
set_callback(:execute, :before, ...)
end

def after_execute(...)
set_callback(:execute, :after, ...)
end

def around_execute(...)
set_callback(:execute, :around, ...)
end
end
end

0 comments on commit a1a5cb3

Please sign in to comment.