module ActiveModel::Jobs

Include this module into your model to take advantage of automatically-generated :job_name! action methods for any matching ActiveJob classes.

@example

class MyModel < ActiveRecord::Base
  include ActiveModel::Jobs

  after_commit :deploy!
end

Constants

ACTION_SUFFIX

Method suffix for actions.

VERSION

@type [String]

Public Instance Methods

method_missing(method, *arguments) click to toggle source

Call perform_later on an ActiveJob class corresponding to an undefined action method name. Most of the work here is done in the Performer class, which takes care of discoevering whether the method passed in corresponds to a given job or whether we should just delegate back to ActiveRecord::Base. This method will prevent a new Perfomer class from being instantiated for every method call by using a guard clause to check whether the method is an action method before proceeding on further checks.

@throws NoMethodError if no job matches the action method

Calls superclass method
# File lib/active_model/jobs.rb, line 34
def method_missing(method, *arguments)
  performer = Performer.new method, model_name
  return super unless respond_to?(method) && performer.job?

  self.class.define_method(method) { performer.call self }
  performer.call self
end
respond_to_missing?(method, include_private = true) click to toggle source

Allow the model to respond to all “action” methods (methods suffixed by +!+)

Calls superclass method
# File lib/active_model/jobs.rb, line 44
def respond_to_missing?(method, include_private = true)
  method.to_s.end_with?(ACTION_SUFFIX) || super
end