Class: Crontab::Entry
- Inherits:
-
Object
- Object
- Crontab::Entry
- Defined in:
- lib/crontab/entry.rb
Overview
A class which represents a job line in crontab(5).
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#schedule ⇒ Object
readonly
Returns the value of attribute schedule.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Class Method Summary collapse
-
.parse(line, options = {}) ⇒ Object
Parses a string line in crontab(5) job format.
Instance Method Summary collapse
-
#initialize(schedule, command, uid = nil) ⇒ Entry
constructor
Creates a crontab(5) entry.
Constructor Details
#initialize(schedule, command, uid = nil) ⇒ Entry
Creates a crontab(5) entry.
-
schedule
A Crontab::Schedule instance. -
command
-
uid
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/crontab/entry.rb', line 9 def initialize(schedule, command, 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 @uid = case uid when String Etc.getpwnam(uid).uid when Integer uid when nil Process.uid else raise ArgumentError, 'invalid uid' end end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
28 29 30 |
# File 'lib/crontab/entry.rb', line 28 def command @command end |
#schedule ⇒ Object (readonly)
Returns the value of attribute schedule.
28 29 30 |
# File 'lib/crontab/entry.rb', line 28 def schedule @schedule end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
28 29 30 |
# File 'lib/crontab/entry.rb', line 28 def uid @uid end |
Class Method Details
.parse(line, options = {}) ⇒ Object
Parses a string line in crontab(5) job format.
-
options[:system]
when true system wide crontab is assumed and@uid
is extracted from line.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/crontab/entry.rb', line 34 def parse(line, ={}) = { :system => false }.merge() line = line.strip number_of_fields = 1 number_of_fields += line.start_with?('@') ? 1 : 5 number_of_fields += 1 if [:system] words = line.split(/\s+/, number_of_fields) command = words.pop uid = [:system] ? words.pop : Process.uid spec = words.join(' ') schedule = Crontab::Schedule.new(spec) new(schedule, command, uid) end |