/
default.rb
69 lines (58 loc) · 1.57 KB
/
default.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module Whenever
module Job
class Default
attr_accessor :task, :at, :redirect
def initialize(options = {})
@task = options[:task]
@at = options[:at]
@redirect = options[:output]
@environment = options[:environment] || :production
@path = options[:path] || Whenever.path
end
def output
task
end
def redirect_output
case @redirect
when String
redirect_from_string
when Hash
redirect_from_hash
when NilClass
" >> /dev/null 2>&1"
else
''
end
end
protected
def stdout
return unless @redirect.has_key?(:standard)
@redirect[:standard].nil? ? '/dev/null' : @redirect[:standard]
end
def stderr
return unless @redirect.has_key?(:error)
@redirect[:error].nil? ? '/dev/null' : @redirect[:error]
end
def redirect_from_hash
case
when stdout == '/dev/null' && stderr == '/dev/null'
" >> /dev/null 2>&1"
when stdout && stderr
" >> #{stdout} 2> #{stderr}"
when stderr
" 2> #{stderr}"
when stdout
" >> #{stdout}"
else
''
end
end
def redirect_from_string
" >> #{@redirect} 2>&1"
end
def path_required
raise ArgumentError, "No path available; set :path, '/your/path' in your schedule file" if @path.blank?
end
end
end
end