Method: Cronman::Entry#initialize

Defined in:
lib/cronman/entry.rb

#initialize(schedule, command, cron_definition, uid = nil) ⇒ Entry

Creates a crontab(5) entry.

  • schedule A Cronman::Schedule instance.

  • command

  • uid

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cronman/entry.rb', line 12

def initialize(schedule, command, cron_definition, uid=nil)
  raise ArgumentError, 'invalid schedule' unless schedule.is_a? Schedule
  raise ArgumentError, 'invalid command' unless command.is_a? String

  @schedule = schedule.freeze
  @command = command.freeze
  @cron_definition = cron_definition.freeze
  @sha1 = Digest::SHA1.hexdigest(@cron_definition + ' ' + @command)
  @translation = Cron2English.parse(@cron_definition).freeze
  @uid =
    case uid
    when String
      Etc.getpwnam(uid).uid
    when Integer
      uid
    when nil
      Process.uid
    else
      raise ArgumentError, 'invalid uid'
    end
end