Class: Winever::CronEntry

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cron_line) ⇒ CronEntry

Returns a new instance of CronEntry.



11
12
13
14
15
16
# File 'lib/winever/cron_entry.rb', line 11

def initialize(cron_line)
  @cron_line = cron_line
  @cron_parts = cron_line.split("|", 5)
  cron_time_string, @task_folder, @task_name, @working_directory, @parameters = @cron_parts
  @cron_time = Winever::CronTime.new(cron_time_string)
end

Instance Attribute Details

#cron_lineObject

Returns the value of attribute cron_line.



3
4
5
# File 'lib/winever/cron_entry.rb', line 3

def cron_line
  @cron_line
end

#cron_timeObject

Returns the value of attribute cron_time.



3
4
5
# File 'lib/winever/cron_entry.rb', line 3

def cron_time
  @cron_time
end

#parametersObject

Returns the value of attribute parameters.



3
4
5
# File 'lib/winever/cron_entry.rb', line 3

def parameters
  @parameters
end

#task_folderObject

Returns the value of attribute task_folder.



3
4
5
# File 'lib/winever/cron_entry.rb', line 3

def task_folder
  @task_folder
end

#task_nameObject

Returns the value of attribute task_name.



3
4
5
# File 'lib/winever/cron_entry.rb', line 3

def task_name
  @task_name
end

#working_directoryObject

Returns the value of attribute working_directory.



3
4
5
# File 'lib/winever/cron_entry.rb', line 3

def working_directory
  @working_directory
end

Class Method Details

.from_cron_output(cron_output, include_invalid = false) ⇒ Object



5
6
7
8
9
# File 'lib/winever/cron_entry.rb', line 5

def self.from_cron_output cron_output, include_invalid=false
  entries = cron_output.split("\n").reject(&:empty?).map{|o| new(o)}
  entries = entries.select(&:valid?) unless include_invalid
  entries
end

Instance Method Details

#invalid_reasonObject



26
27
28
29
30
31
# File 'lib/winever/cron_entry.rb', line 26

def invalid_reason
  return "Doesn't match the Winever format" unless @cron_parts.length == 5
  return "Doesn't have a task_name specified" if @task_name.nil? || @task_name.empty?
  return "Problem with schedule: #{@cron_time.unsupported_reason}" unless @cron_time.supported?
  nil
end

#triggersObject



18
19
20
# File 'lib/winever/cron_entry.rb', line 18

def triggers
  @cron_time.triggers
end

#valid?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/winever/cron_entry.rb', line 22

def valid?
  invalid_reason.nil?
end