module Motion::Component::Lifecycle

Public Instance Methods

_run_action_callbacks(context:, &block) click to toggle source
# File lib/motion/component/lifecycle.rb, line 103
def _run_action_callbacks(context:, &block)
  @_action_callback_context = context

  run_callbacks(:action, &block)
ensure
  @_action_callback_context = nil
end
action_callback_context_filter(contexts, invert: false) click to toggle source
# File lib/motion/component/lifecycle.rb, line 68
def action_callback_context_filter(contexts, invert: false)
  proc { contexts.include?(@_action_callback_context) ^ invert }
end
after_action(*methods, **options, &block) click to toggle source
# File lib/motion/component/lifecycle.rb, line 40
def after_action(*methods, **options, &block)
  set_action_callback(:after, *methods, **options, &block)
end
after_connect(*methods, **options, &block) click to toggle source
# File lib/motion/component/lifecycle.rb, line 44
def after_connect(*methods, **options, &block)
  set_callback(:connect, :after, *methods, **options, &block)
end
after_disconnect(*methods, **options, &block) click to toggle source
# File lib/motion/component/lifecycle.rb, line 48
def after_disconnect(*methods, **options, &block)
  set_callback(:disconnect, :after, *methods, **options, &block)
end
around_action(*methods, **options, &block) click to toggle source
# File lib/motion/component/lifecycle.rb, line 36
def around_action(*methods, **options, &block)
  set_action_callback(:around, *methods, **options, &block)
end
before_action(*methods, **options, &block) click to toggle source
# File lib/motion/component/lifecycle.rb, line 32
def before_action(*methods, **options, &block)
  set_action_callback(:before, *methods, **options, &block)
end
process_connect() click to toggle source
# File lib/motion/component/lifecycle.rb, line 73
def process_connect
  _run_connect_callbacks

  # TODO: Remove at next minor release
  if respond_to?(:connected)
    ActiveSupport::Deprecation.warn(
      "The `connected` lifecycle method is being replaced by the " \
      "`after_connect` callback and will no longer be automatically " \
      "invoked in the next **minor release** of Motion."
    )

    send(:connected)
  end
end
process_disconnect() click to toggle source
# File lib/motion/component/lifecycle.rb, line 88
def process_disconnect
  _run_disconnect_callbacks

  # TODO: Remove at next minor release
  if respond_to?(:disconnected)
    ActiveSupport::Deprecation.warn(
      "The `disconnected` lifecycle method is being replaced by the " \
      "`after_disconnect` callback and will no longer be automatically " \
      "invoked in the next **minor release** of Motion."
    )

    send(:disconnected)
  end
end
set_action_callback(kind, *methods, **options, &block) click to toggle source
# File lib/motion/component/lifecycle.rb, line 54
def set_action_callback(kind, *methods, **options, &block)
  filters = Array(options.delete(:if))

  if (only = Array(options.delete(:only))).any?
    filters << action_callback_context_filter(only)
  end

  if (except = Array(options.delete(:except))).any?
    filters << action_callback_context_filter(except, invert: true)
  end

  set_callback(:action, kind, *methods, if: filters, **options, &block)
end
upgrade_from(previous_revision, instance) click to toggle source
# File lib/motion/component/lifecycle.rb, line 24
def upgrade_from(previous_revision, instance)
  raise UpgradeNotImplementedError.new(
    instance,
    previous_revision,
    Motion.config.revision
  )
end