Class: Whenever::CommandLine

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CommandLine

Returns a new instance of CommandLine.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/command_line.rb', line 8

def initialize(options={})
  @options = options
  
  @options[:file]        ||= 'config/schedule.rb'
  @options[:identifier]  ||= default_identifier
  @options[:environment] ||= :production
  
  unless File.exists?(@options[:file])
    warn("[fail] Can't find file: #{@options[:file]}")
    exit(1)
  end

  if @options[:update] && @options[:write]
    warn("[fail] Can't update AND write. choose one.")
    exit(1)
  end
end

Class Method Details

.execute(options = {}) ⇒ Object



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

def self.execute(options={})
  new(options).run
end

Instance Method Details

#runObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/command_line.rb', line 26

def run
  if @options[:update]
    write_crontab(updated_crontab)
  elsif @options[:write]
    write_crontab(whenever_cron)
  else
    puts Whenever.cron(:file => @options[:file], :environment => @options[:environment])
    exit
  end
end