Class: Whenever::JobSequence

Inherits:
Array
  • Object
show all
Defined in:
lib/whenever/job_sequence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, size = 0, obj = nil) ⇒ JobSequence

Returns a new instance of JobSequence.



5
6
7
8
9
10
# File 'lib/whenever/job_sequence.rb', line 5

def initialize(options={}, size=0, obj=nil)
  super(size, obj)
  
  @options = options
  @dependent = options.fetch(:dependent, true)
end

Instance Attribute Details

#dependent=(value) ⇒ Object (writeonly)

Sets the attribute dependent

Parameters:

  • value

    the value to set the attribute dependent to.



3
4
5
# File 'lib/whenever/job_sequence.rb', line 3

def dependent=(value)
  @dependent = value
end

Instance Method Details

#to_single_jobObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/whenever/job_sequence.rb', line 12

def to_single_job
  options = @options.dup
  default_redirection = options.delete(:output)
  
  concatenation = @dependent ? " && " : "; "
  tasks_with_redirection = map do |t|
    if redirection = t.output_redirection.nil? || t.output_redirection == :not_set ? default_redirection : t.output_redirection
      t.output + " " + Output::Cron::OutputRedirection.new(redirection).to_s
    else
      t.output
    end
  end
  
  single_task = tasks_with_redirection.join(concatenation)

  Job::Default.new(options.merge(:task => single_task))
end