Module: ActiveModel::Jobs
- Defined in:
- lib/active_model/jobs.rb,
lib/active_model/jobs/engine.rb,
lib/active_model/jobs/version.rb,
lib/active_model/jobs/performer.rb
Overview
Include this module into your model to take advantage of automatically-generated :job_name! action methods for any matching ActiveJob classes.
Defined Under Namespace
Constant Summary collapse
- ACTION_SUFFIX =
Method suffix for actions.
'!'- VERSION =
"0.2.2".freeze
Instance Method Summary collapse
-
#method_missing(method, *arguments) ⇒ Object
Call
perform_lateron an ActiveJob class corresponding to an undefined action method name. -
#respond_to_missing?(method, include_private = true) ⇒ Boolean
Allow the model to respond to all “action” methods (methods suffixed by !).
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments) ⇒ Object
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.
34 35 36 37 38 39 40 |
# 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 |
Instance Method Details
#respond_to_missing?(method, include_private = true) ⇒ Boolean
Allow the model to respond to all “action” methods (methods suffixed by !)
44 45 46 |
# 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 |