class Khronotab::CronTab

Constants

VERSION

Attributes

comments[RW]
jobs[RW]
variables[RW]

Public Class Methods

new(opt={}) click to toggle source
# File lib/khronotab.rb, line 14
def initialize(opt={})
  @variables ||= []
  @jobs ||= []
  @comments ||= []
  self.read_from_file(opt[:file]) if opt[:file] 
end
read_from_file(*args) click to toggle source
# File lib/khronotab.rb, line 21
def self.read_from_file(*args)
  self.new.read_from_file(*args)
end

Public Instance Methods

read_from_file(filename) click to toggle source
# File lib/khronotab.rb, line 25
def read_from_file(filename)
  File.open(filename, 'r').readlines.each do |line|
    if CronVariable.matches?(line)
      @variables << CronVariable.add_new(line)
    elsif CronJob.matches?(line)
      @jobs << CronJob.add_new(line)
    elsif CronComment.matches?(line)
      @comments << line
    else
      STDERR.puts("Warning: Line is not valid!(#{line.chomp})")
    end
  end
self
end
write_to_file(filename) click to toggle source
# File lib/khronotab.rb, line 40
def write_to_file(filename)
  #TODO: Have this validate a file or append to the file if there
  # is new data. Just overwriting the damn thing isn't very
  # safe or wise.. -kmwhite 2010.04.19
  crontab = File.open(filename,'w')
  @variables.each do |variable|
    crontab.puts definition.to_line
  end
  @jobs.each do |job|
    crontab.puts job.to_line
  end
  crontab.flush
  crontab.close
end