Class: Whenever::Job
- Inherits:
-
Object
- Object
- Whenever::Job
- Defined in:
- lib/whenever/job.rb
Instance Attribute Summary collapse
-
#at ⇒ Object
readonly
Returns the value of attribute at.
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
Instance Method Summary collapse
- #has_role?(role) ⇒ Boolean
-
#initialize(options = {}) ⇒ Job
constructor
A new instance of Job.
- #output ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Job
Returns a new instance of Job.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/whenever/job.rb', line 7 def initialize( = {}) @options = @at = .delete(:at) @template = .delete(:template) @job_template = .delete(:job_template) || ":job" @roles = Array.wrap(.delete(:roles)) @options[:output] = .has_key?(:output) ? Whenever::Output::Redirection.new([:output]).to_s : '' @options[:environment] ||= :production @options[:path] = Shellwords.shellescape(@options[:path] || Whenever.path) end |
Instance Attribute Details
#at ⇒ Object (readonly)
Returns the value of attribute at.
5 6 7 |
# File 'lib/whenever/job.rb', line 5 def at @at end |
#roles ⇒ Object (readonly)
Returns the value of attribute roles.
5 6 7 |
# File 'lib/whenever/job.rb', line 5 def roles @roles end |
Instance Method Details
#has_role?(role) ⇒ Boolean
27 28 29 |
# File 'lib/whenever/job.rb', line 27 def has_role?(role) roles.empty? || roles.include?(role) end |
#output ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/whenever/job.rb', line 18 def output job = process_template(@template, @options).strip out = process_template(@job_template, { :job => job }).strip if out =~ /\n/ raise ArgumentError, "Task contains newline" end out.gsub(/%/, '\%') end |