Module: RocketJob::Plugins::Job::Model::ClassMethods
- Defined in:
- lib/rocket_job/plugins/job/model.rb
Instance Method Summary collapse
-
#collective_name ⇒ Object
Returns [String] the collective name for this job class.
-
#collective_name=(collective_name) ⇒ Object
Allow the collective name for this job class to be overridden.
-
#field(name, options) ⇒ Field
Defines all the fields that are accessible on the Document For each field that is defined, a getter and setter will be added as an instance method to the Document.
-
#human_name ⇒ Object
Returns [String] the human readable name for this job class.
-
#human_name=(human_name) ⇒ Object
Allow the human readable job name for this job class to be overridden.
-
#public_rocket_job_properties(*args) ⇒ Object
DEPRECATED.
-
#queued_now ⇒ Object
Scope for queued jobs that can run now I.e.
-
#rocket_job {|_self| ... } ⇒ Object
DEPRECATED.
-
#scheduled ⇒ Object
Scope for jobs scheduled to run in the future.
-
#underscore_name ⇒ Object
Returns [String] the singular name for this job class.
-
#underscore_name=(underscore_name) ⇒ Object
Allow the collective name for this job class to be overridden.
Instance Method Details
#collective_name ⇒ Object
Returns [String] the collective name for this job class
Example:
job = DataStudyJob.new
job.collective_name
# => "data_studies"
142 143 144 |
# File 'lib/rocket_job/plugins/job/model.rb', line 142 def collective_name @collective_name ||= name.sub(/Job$/, '').pluralize.underscore end |
#collective_name=(collective_name) ⇒ Object
Allow the collective name for this job class to be overridden
147 148 149 |
# File 'lib/rocket_job/plugins/job/model.rb', line 147 def collective_name=(collective_name) @collective_name = collective_name end |
#field(name, options) ⇒ Field
Defines all the fields that are accessible on the Document For each field that is defined, a getter and setter will be added as an instance method to the Document.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/rocket_job/plugins/job/model.rb', line 179 def field(name, ) if .delete(:user_editable) == true self.user_editable_fields += [name.to_sym] unless user_editable_fields.include?(name.to_sym) end if .delete(:class_attribute) == true class_attribute(name, instance_accessor: false) if .has_key?(:default) public_send("#{name}=", [:default]) end [:default] = lambda { self.class.public_send(name) } end if .delete(:copy_on_restart) == true self.rocket_job_restart_attributes += [name.to_sym] unless rocket_job_restart_attributes.include?(name.to_sym) end super(name, ) end |
#human_name ⇒ Object
Returns [String] the human readable name for this job class
Example:
job = DataStudyJob.new
job.human_name
# => "Data Study"
127 128 129 |
# File 'lib/rocket_job/plugins/job/model.rb', line 127 def human_name @human_name ||= name.sub(/Job$/, '').titleize end |
#human_name=(human_name) ⇒ Object
Allow the human readable job name for this job class to be overridden
132 133 134 |
# File 'lib/rocket_job/plugins/job/model.rb', line 132 def human_name=(human_name) @human_name = human_name end |
#public_rocket_job_properties(*args) ⇒ Object
DEPRECATED
203 204 205 206 |
# File 'lib/rocket_job/plugins/job/model.rb', line 203 def public_rocket_job_properties(*args) warn "Replace calls to .public_rocket_job_properties by adding `user_editable: true` option to the field declaration in #{name} for: #{args.inspect}" self.user_editable_fields += args.collect(&:to_sym) end |
#queued_now ⇒ Object
Scope for queued jobs that can run now I.e. Queued jobs excluding scheduled jobs
158 159 160 |
# File 'lib/rocket_job/plugins/job/model.rb', line 158 def queued_now queued.or({:run_at => nil}, {:run_at.lte => Time.now}) end |
#rocket_job {|_self| ... } ⇒ Object
DEPRECATED
197 198 199 200 |
# File 'lib/rocket_job/plugins/job/model.rb', line 197 def rocket_job warn 'Replace calls to .rocket_job with calls to set class instance variables. For example: self.priority = 50' yield(self) end |
#scheduled ⇒ Object
Scope for jobs scheduled to run in the future
152 153 154 |
# File 'lib/rocket_job/plugins/job/model.rb', line 152 def scheduled queued.where(:run_at.gt => Time.now) end |
#underscore_name ⇒ Object
Returns [String] the singular name for this job class
Example:
job = DataStudyJob.new
job.underscore_name
# => "data_study"
112 113 114 |
# File 'lib/rocket_job/plugins/job/model.rb', line 112 def underscore_name @underscore_name ||= name.sub(/Job$/, '').underscore end |
#underscore_name=(underscore_name) ⇒ Object
Allow the collective name for this job class to be overridden
117 118 119 |
# File 'lib/rocket_job/plugins/job/model.rb', line 117 def underscore_name=(underscore_name) @underscore_name = underscore_name end |