Class: ActiveModel::Jobs::Performer Private
- Inherits:
-
Object
- Object
- ActiveModel::Jobs::Performer
- Defined in:
- lib/active_model/jobs/performer.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A support class for finding the ActiveJob::Base
that corresponds to a given action method on a given model. When the job class is found, the action method fires off a new instance of the job.
Constant Summary collapse
- BANG =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/!\Z/
Instance Attribute Summary collapse
- #method_name ⇒ Object readonly private
- #model_name ⇒ Object readonly private
Instance Method Summary collapse
-
#action_name ⇒ Object
private
Strip the ‘!’ off of the end of the method.
-
#call(model) ⇒ Object
private
Perform this action on the given model.
-
#initialize(method_name, model_name) ⇒ Performer
constructor
private
A new instance of Performer.
-
#job? ⇒ Boolean
private
Tests whether this method name corresponds to a job class in the application.
-
#job_class ⇒ Object
private
Attempts to find the job class for this method and return it, otherwise it returns
nil
when encountering aNameError
. -
#job_name ⇒ Object
private
Build the conventional job name from the given method and model.
Constructor Details
#initialize(method_name, model_name) ⇒ Performer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Performer.
24 25 26 27 |
# File 'lib/active_model/jobs/performer.rb', line 24 def initialize(method_name, model_name) @method_name = method_name.to_s @model_name = model_name.to_s end |
Instance Attribute Details
#method_name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/active_model/jobs/performer.rb', line 16 def method_name @method_name end |
#model_name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/active_model/jobs/performer.rb', line 20 def model_name @model_name end |
Instance Method Details
#action_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Strip the ‘!’ off of the end of the method.
60 61 62 |
# File 'lib/active_model/jobs/performer.rb', line 60 def action_name method_name.gsub BANG, '' end |
#call(model) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Perform this action on the given model.
68 69 70 71 |
# File 'lib/active_model/jobs/performer.rb', line 68 def call(model) return false unless job? job_class.perform_later model end |
#job? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Tests whether this method name corresponds to a job class in the application.
33 34 35 |
# File 'lib/active_model/jobs/performer.rb', line 33 def job? method_name =~ BANG && job_class.present? end |
#job_class ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Attempts to find the job class for this method and return it, otherwise it returns nil
when encountering a NameError
.
41 42 43 44 45 |
# File 'lib/active_model/jobs/performer.rb', line 41 def job_class job_name.classify.constantize rescue NameError nil end |
#job_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build the conventional job name from the given method and model. Suffix with job
and separate with underscores.
51 52 53 54 55 |
# File 'lib/active_model/jobs/performer.rb', line 51 def job_name [ action_name, model_name, 'job' ].join '_' end |