Class: Do::Task

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

Overview

A single declared task parsed from the TOML configuration.

Tasks are plain Ruby objects; the Validator is responsible for deciding whether their field values are acceptable. This class only carries data and exposes a few derived helpers.

Constant Summary collapse

SCHEDULES =
%w[once hourly daily weekly monthly].freeze
WEEKDAY_NAMES =
%w[monday tuesday wednesday thursday friday saturday sunday].freeze
WEEKDAY_NUMBERS =
{
  'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4,
  'friday' => 5, 'saturday' => 6, 'sunday' => 7
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, command:, schedule: nil, time: nil, day: nil, working_directory: nil, environment: {}, enabled: nil, raw: {}) ⇒ Task

Returns a new instance of Task.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/do/task.rb', line 18

def initialize(name:, command:, schedule: nil, time: nil, day: nil,
               working_directory: nil, environment: {}, enabled: nil, raw: {})
  @name = name
  @command = command
  @schedule = schedule
  @time = time
  @day = day
  @working_directory = working_directory
  @environment = environment || {}
  @enabled = enabled
  @raw = raw
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



15
16
17
# File 'lib/do/task.rb', line 15

def command
  @command
end

#dayObject (readonly)

Returns the value of attribute day.



15
16
17
# File 'lib/do/task.rb', line 15

def day
  @day
end

#environmentObject (readonly)

Returns the value of attribute environment.



15
16
17
# File 'lib/do/task.rb', line 15

def environment
  @environment
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/do/task.rb', line 15

def name
  @name
end

#rawObject (readonly)

Returns the value of attribute raw.



15
16
17
# File 'lib/do/task.rb', line 15

def raw
  @raw
end

#scheduleObject (readonly)

Returns the value of attribute schedule.



15
16
17
# File 'lib/do/task.rb', line 15

def schedule
  @schedule
end

#timeObject (readonly)

Returns the value of attribute time.



15
16
17
# File 'lib/do/task.rb', line 15

def time
  @time
end

#working_directoryObject (readonly)

Returns the value of attribute working_directory.



15
16
17
# File 'lib/do/task.rb', line 15

def working_directory
  @working_directory
end

Instance Method Details

#enabled?Boolean

enabled is true by default for scheduled tasks and false for manual-only (unscheduled) tasks.

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'lib/do/task.rb', line 33

def enabled?
  return scheduled? if @enabled.nil?
  return @enabled == 'true' || @enabled == true if @enabled.is_a?(String)

  !!@enabled
end

#scheduled?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/do/task.rb', line 40

def scheduled?
  !@schedule.nil? && @schedule != ''
end

#service_unitObject

Return the service unit name systemd will use for this task.



45
46
47
# File 'lib/do/task.rb', line 45

def service_unit
  "do-#{name}.service"
end

#timer_unitObject



49
50
51
# File 'lib/do/task.rb', line 49

def timer_unit
  "do-#{name}.timer"
end