Module: MimeActor::Callbacks

Extended by:
ActiveSupport::Concern
Includes:
ActiveSupport::Callbacks, Validator
Included in:
Stage
Defined in:
lib/mime_actor/callbacks.rb

Overview

# MimeActor Callbacks

MimeActor provides hooks during the life cycle of an act. Available callbacks are:

  • append_act_before

  • append_act_around

  • append_act_after

  • act_before

  • act_around

  • act_after

  • prepend_act_before

  • prepend_act_around

  • prepend_act_after

NOTE: Calling the same callback multiple times will overwrite previous callback definitions.

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

LIFECYCLES =
i[before after around].freeze

Instance Method Summary collapse

Instance Method Details

#run_act_callbacks(action:, format:) ⇒ Object

Callbacks invocation sequence depends on the order of callback definition.

Examples:

callbacks with/without action filter

act_before :my_act_before_one
act_before :my_act_before_two, action: :create
act_before :my_act_before_three

act_around :my_act_around_one
act_around :my_act_around_two, action: :create
act_around :my_act_around_three

act_after :my_act_after_one
act_after :my_act_after_two, action: :create
act_after :my_act_after_three

# actual sequence:
# - my_act_before_one
# - my_act_before_two
# - my_act_before_three
# - my_act_around_one
# - my_act_around_two
# - my_act_around_three
# - my_act_after_three
# - my_act_after_two
# - my_act_after_one

callbacks with format filter

act_before :my_act_before_one
act_before :my_act_before_two, action: :create
act_before :my_act_before_three, action: :create, format: :html
act_before :my_act_before_four

act_around :my_act_around_one
act_around :my_act_around_two, action: :create, format: :html
act_around :my_act_around_three, action: :create
act_around :my_act_around_four

act_after :my_act_after_one, format: :html
act_after :my_act_after_two
act_after :my_act_after_three, action: :create
act_after :my_act_after_four

# actual sequence:
# - my_act_before_one
# - my_act_before_two
# - my_act_before_four
# - my_act_before_three
# - my_act_around_one
# - my_act_around_two
# - my_act_around_three
# - my_act_around_four
# - my_act_after_four
# - my_act_after_three
# - my_act_after_two
# - my_act_after_one


187
188
189
190
191
192
193
194
# File 'lib/mime_actor/callbacks.rb', line 187

def run_act_callbacks(action:, format:)
  @_act_action = action.to_sym
  @_act_format = format.to_sym

  run_callbacks :act do
    yield if block_given?
  end
end