class TabKeeper::Generator
Public Class Methods
new(*pipeline)
click to toggle source
# File lib/tab_keeper/generator.rb, line 3 def initialize(*pipeline) @pipeline = pipeline.flatten end
Public Instance Methods
generate(job_list, **options)
click to toggle source
# File lib/tab_keeper/generator.rb, line 7 def generate(job_list, **options) rows = rows(job_list, **options) validate_rows!(rows) rows.join("\n\n") + "\n" end
Private Instance Methods
apply_pipeline(job, timing, **options)
click to toggle source
# File lib/tab_keeper/generator.rb, line 28 def apply_pipeline(job, timing, **options) @pipeline.reduce(nil) do |previous, pipe| pipe.new(previous, job: job, timing: timing, **options).to_s end end
cron_escape(input)
click to toggle source
# File lib/tab_keeper/generator.rb, line 34 def cron_escape(input) input.chars.map { |char| char == '%' ? "\\%" : char }.join end
rows(job_list, **options)
click to toggle source
# File lib/tab_keeper/generator.rb, line 22 def rows(job_list, **options) job_list.map do |job, timing| timing + " " + cron_escape(apply_pipeline(job, timing, **options)) end end
validate_rows!(rows)
click to toggle source
# File lib/tab_keeper/generator.rb, line 15 def validate_rows!(rows) too_long_rows = rows.reject { |row| row.length < 900 } return unless too_long_rows.any? raise "The following rows are too long for a cron file, and may be truncated:\n" \ "#{too_long_rows.join("\n\n")}" end