improve eval'ing of schedule file to reveal the filename in backtraces

This commit is contained in:
Javan Makhmali 2011-07-31 14:16:23 -04:00
parent 8bb0f04131
commit ab877e3cbb

View File

@ -3,21 +3,20 @@ module Whenever
def initialize(options) def initialize(options)
@jobs, @env, @set_variables, @pre_set_variables = {}, {}, {}, {} @jobs, @env, @set_variables, @pre_set_variables = {}, {}, {}, {}
case options if options.is_a? String
when String options = { :string => options }
config = options
when Hash
config = if options[:string]
options[:string]
elsif options[:file]
File.read(options[:file])
end
pre_set(options[:set])
end end
pre_set(options[:set])
setup = File.read("#{File.expand_path(File.dirname(__FILE__))}/setup.rb") setup = File.read("#{File.expand_path(File.dirname(__FILE__))}/setup.rb")
schedule = if options[:string]
options[:string]
elsif options[:file]
File.read(options[:file])
end
eval(setup + config) instance_eval(setup + schedule, options[:file] || '<eval>')
end end
def set(variable, value) def set(variable, value)