Class: CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/command_line.rb

Constant Summary collapse

START_MARKER =
"### BEGIN whenever generated crontab ###"
END_MARKER =
"### END   whenever generated crontab ###"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CommandLine

Returns a new instance of CommandLine.



15
16
17
18
# File 'lib/command_line.rb', line 15

def initialize(options = {})
  @options = options
  @marker = options[:marker] || "whenever generated crontab"
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/command_line.rb', line 5

def options
  @options
end

Instance Method Details

#end_markerObject



11
12
13
# File 'lib/command_line.rb', line 11

def end_marker
  "### END   #{@marker} ###"
end

#start_markerObject



7
8
9
# File 'lib/command_line.rb', line 7

def start_marker
  "### BEGIN #{@marker} ###"
end

#update!Object



25
26
27
28
29
# File 'lib/command_line.rb', line 25

def update!
  before, after = strip_whenever_crontab(read_crontab)
  whenever_cron = Whenever.cron(options)
  write_crontab((before + [start_marker, whenever_cron, end_marker] + after).compact.join("\n"))
end

#write!Object



20
21
22
23
# File 'lib/command_line.rb', line 20

def write!
  cron_output = Whenever.cron(options)
  write_crontab(cron_output)
end