Class: Whenever::JobList
- Inherits:
-
Object
show all
- Defined in:
- lib/whenever/job_list.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options) ⇒ JobList
Returns a new instance of JobList.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/whenever/job_list.rb', line 5
def initialize(options)
@jobs, @env, @set_variables, @pre_set_variables = {}, {}, {}, {}
if options.is_a? String
options = { :string => options }
end
pre_set(options[:set])
@roles = options[:roles] || []
setup_file = File.expand_path('../setup.rb', __FILE__)
setup = File.read(setup_file)
schedule = if options[:string]
options[:string]
elsif options[:file]
File.read(options[:file])
end
instance_eval(setup, setup_file)
instance_eval(schedule, options[:file] || '<eval>')
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
36
37
38
|
# File 'lib/whenever/job_list.rb', line 36
def method_missing(name, *args, &block)
@set_variables.has_key?(name) ? @set_variables[name] : super
end
|
Instance Attribute Details
#roles ⇒ Object
Returns the value of attribute roles.
3
4
5
|
# File 'lib/whenever/job_list.rb', line 3
def roles
@roles
end
|
Class Method Details
.respond_to?(name, include_private = false) ⇒ Boolean
40
41
42
|
# File 'lib/whenever/job_list.rb', line 40
def self.respond_to?(name, include_private = false)
@set_variables.has_key?(name) || super
end
|
Instance Method Details
#env(variable, value) ⇒ Object
44
45
46
|
# File 'lib/whenever/job_list.rb', line 44
def env(variable, value)
@env[variable.to_s] = value
end
|
#every(frequency, options = {}) ⇒ Object
48
49
50
51
52
|
# File 'lib/whenever/job_list.rb', line 48
def every(frequency, options = {})
@current_time_scope = frequency
@options = options
yield
end
|
#generate_cron_output ⇒ Object
74
75
76
|
# File 'lib/whenever/job_list.rb', line 74
def generate_cron_output
[environment_variables, cron_jobs].compact.join
end
|
#job_type(name, template) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/whenever/job_list.rb', line 54
def job_type(name, template)
singleton_class.class_eval do
define_method(name) do |task, *args|
options = { :task => task, :template => template }
options.merge!(args[0]) if args[0].is_a? Hash
options[:mailto] ||= @options.fetch(:mailto, :default_mailto)
options[:output] = (options[:cron_log] || @cron_log) if defined?(@cron_log) || options.has_key?(:cron_log)
options[:output] = @output if defined?(@output) && !options.has_key?(:output)
@jobs[options.fetch(:mailto)] ||= {}
@jobs[options.fetch(:mailto)][@current_time_scope] ||= []
@jobs[options.fetch(:mailto)][@current_time_scope] << Whenever::Job.new(@options.merge(@set_variables).merge(options))
end
end
end
|
#set(variable, value) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/whenever/job_list.rb', line 28
def set(variable, value)
variable = variable.to_sym
return if @pre_set_variables[variable]
instance_variable_set("@#{variable}".to_sym, value)
@set_variables[variable] = value
end
|