Class: New::Task

Inherits:
Object
  • Object
show all
Extended by:
Validation
Defined in:
lib/new/task.rb

Overview

New::Task is the base class that all custom tasks need to inherit from

Constant Summary collapse

@@tasks =

global tasks for task class with a getter

{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Validation

validate_class, validate_option

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



41
42
43
# File 'lib/new/task.rb', line 41

def name
  @name
end

#optionsObject

INSTANCE METHODS



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

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



41
42
43
# File 'lib/new/task.rb', line 41

def path
  @path
end

#sourceObject

INSTANCE METHODS



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

def source
  @source
end

Class Method Details

.get_task_name(task_path) ⇒ Object

derive a task name from a task path

Parameters:

  • task_path (String)

    full path to a task ruby file



18
19
20
# File 'lib/new/task.rb', line 18

def get_task_name task_path
  task_path.match(/([^\/]*)_task\.rb$/)[1].to_sym
end

.tasksObject



13
# File 'lib/new/task.rb', line 13

def tasks; @@tasks; end

Instance Method Details

#class_optionsObject



48
49
50
# File 'lib/new/task.rb', line 48

def class_options
  @class_options ||= self.class.class_variable_get :@@options rescue {}
end

#descriptionObject

getters/setters for task meta data stored temporarily on a class var



44
45
46
# File 'lib/new/task.rb', line 44

def description
  @description ||= self.class.class_variable_get :@@description rescue ''
end

#run_command(command) ⇒ Boolean

run a system command

Parameters:

  • command (String)

    the system command to run

Returns:

  • (Boolean)

    true/false based on if the exit status of the command



74
75
76
77
78
79
80
# File 'lib/new/task.rb', line 74

def run_command command
  # if verbose, dont redirect output to null
  command += ' >> /dev/null 2>&1' unless New.verbose

  # run the command
  Kernel.system command
end

#validateObject

validate all options



59
60
61
62
63
64
65
66
67
68
# File 'lib/new/task.rb', line 59

def validate
  class_options.keys.each do |option_name|
    option_settings = class_options[option_name]
    option_value = @options[:task_options][option_name]
    new_option_value = New::Task.validate_option(option_name, option_settings, option_value)

    # set the new validated value
    @options[:task_options][option_name] = new_option_value
  end
end

#verifyObject

task to check that outside dependencies are met before we run the tasks since verify is not a required method, we define a blank one to prevent undefined method errors



55
# File 'lib/new/task.rb', line 55

def verify; end