Class: Whenever::Job

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Job

Returns a new instance of Job.



6
7
8
9
10
11
12
13
# File 'lib/whenever/job.rb', line 6

def initialize(options = {})
  @options = options
  
  @at                      = options[:at]
  @output_redirection      = options.has_key?(:output) ? options[:output] : :not_set
  @options[:environment] ||= :production
  @options[:path]        ||= Whenever.path
end

Instance Attribute Details

#atObject (readonly)

Returns the value of attribute at.



4
5
6
# File 'lib/whenever/job.rb', line 4

def at
  @at
end

#output_redirectionObject (readonly)

Returns the value of attribute output_redirection.



4
5
6
# File 'lib/whenever/job.rb', line 4

def output_redirection
  @output_redirection
end

Instance Method Details

#outputObject



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

def output
  @options[:template].dup.gsub(/:\w+/) do |key|
    before_and_after = [$`[-1..-1], $'[0..0]]
    option = @options[key.sub(':', '').to_sym]

    if before_and_after.all? { |c| c == "'" }
      escape_single_quotes(option)
    elsif before_and_after.all? { |c| c == '"' }
      escape_double_quotes(option)
    else
      option
    end
  end
end