Class: MaintenanceTasks::TaskDataShow Private

Inherits:
Object
  • Object
show all
Defined in:
app/models/maintenance_tasks/task_data_show.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class that represents the data related to a Task. Such information can be sourced from a Task or from existing Run records for a Task that was since deleted. This class contains detailed information such as the source code, associated runs, parameters, etc.

Instances of this class replace a Task class instance in cases where we don’t need the actual Task subclass.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ TaskDataShow

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes a Task Data with a name and optionally a related run.

Parameters:

  • name (String)

    the name of the Task subclass.



17
18
19
# File 'app/models/maintenance_tasks/task_data_show.rb', line 17

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameString (readonly) Also known as: to_s

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the name of the Task.

Returns:

  • (String)

    the name of the Task.



22
23
24
# File 'app/models/maintenance_tasks/task_data_show.rb', line 22

def name
  @name
end

Instance Method Details

#active_runsActiveRecord::Relation<MaintenanceTasks::Run>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the set of currently active Run records associated with the Task.

Returns:



45
46
47
# File 'app/models/maintenance_tasks/task_data_show.rb', line 45

def active_runs
  @active_runs ||= runs.active
end

#codeString?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The Task’s source code.

Returns:

  • (String)

    the contents of the file which defines the Task.

  • (nil)

    if the Task file was deleted.



29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/maintenance_tasks/task_data_show.rb', line 29

def code
  return if deleted?

  task = Task.named(name)
  file = if Object.respond_to?(:const_source_location)
    Object.const_source_location(task.name).first
  else
    task.instance_method(:process).source_location.first
  end
  File.read(file)
end

#completed_runsActiveRecord::Relation<MaintenanceTasks::Run>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the set of completed Run records associated with the Task. This collection represents a historic of past Runs for information purposes, since the base for Task Data information comes primarily from currently active runs.

Returns:



56
57
58
# File 'app/models/maintenance_tasks/task_data_show.rb', line 56

def completed_runs
  @completed_runs ||= runs.completed
end

#csv_task?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether the Task inherits from CsvTask.

Returns:

  • (Boolean)

    whether the Task inherits from CsvTask.



69
70
71
# File 'app/models/maintenance_tasks/task_data_show.rb', line 69

def csv_task?
  !deleted? && Task.named(name).has_csv_content?
end

#deleted?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether the Task has been deleted.

Returns:

  • (Boolean)

    whether the Task has been deleted.



61
62
63
64
65
66
# File 'app/models/maintenance_tasks/task_data_show.rb', line 61

def deleted?
  Task.named(name)
  false
rescue Task::NotFoundError
  true
end

#newMaintenanceTasks::Task?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



84
85
86
87
88
# File 'app/models/maintenance_tasks/task_data_show.rb', line 84

def new
  return if deleted?

  MaintenanceTasks::Task.named(name).new
end

#parameter_namesArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the names of parameters the Task accepts.

Returns:

  • (Array<String>)

    the names of parameters the Task accepts.



74
75
76
77
78
79
80
# File 'app/models/maintenance_tasks/task_data_show.rb', line 74

def parameter_names
  if deleted?
    []
  else
    Task.named(name).attribute_names
  end
end