# File lib/whenever/job.rb, line 7 def initialize(options = {}) @options = options @at = options.delete(:at) @template = options.delete(:template) @job_template = options.delete(:job_template) || ":job" @roles = Array.wrap(options.delete(:roles)) @options[:output] = options.has_key?(:output) ? Whenever::Output::Redirection.new(options[:output]).to_s : '' @options[:environment_variable] ||= "RAILS_ENV" @options[:environment] ||= :production @options[:path] = Shellwords.shellescape(@options[:path] || Whenever.path) end
# File lib/whenever/job.rb, line 28 def has_role?(role) roles.empty? || roles.include?(role) end
# File lib/whenever/job.rb, line 19 def output job = process_template(@template, @options).strip out = process_template(@job_template, { :job => job }).strip if out =~ /\n/ raise ArgumentError, "Task contains newline" end out.gsub(/%/, '\%') end
# File lib/whenever/job.rb, line 53 def escape_double_quotes(str) str.gsub(/"/) { '\"' } end
# File lib/whenever/job.rb, line 49 def escape_single_quotes(str) str.gsub(/'/) { "'\\''" } end
# File lib/whenever/job.rb, line 34 def process_template(template, options) template.gsub(/:\w+/) do |key| before_and_after = [$`[-1..-1], $'[0..0]] option = options[key.sub(':', '').to_sym] || key 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