Class: MaintenanceTasks::TaskDataShow Private
- Inherits:
-
Object
- Object
- MaintenanceTasks::TaskDataShow
- 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
-
#name ⇒ String
(also: #to_s)
readonly
private
The name of the Task.
-
#runs_page ⇒ RunsPage
readonly
private
The current page of completed runs, based on the cursor passed in initialize.
Class Method Summary collapse
-
.prepare(name, runs_cursor: nil, arguments: nil) ⇒ Object
private
Prepares a Task Data from a task name.
Instance Method Summary collapse
-
#active_runs ⇒ ActiveRecord::Relation<MaintenanceTasks::Run>
private
Returns the set of currently active Run records associated with the Task.
-
#code ⇒ String?
private
The Task’s source code.
-
#completed_runs ⇒ ActiveRecord::Relation<MaintenanceTasks::Run>
private
Returns the set of completed Run records associated with the Task.
-
#csv_task? ⇒ Boolean
private
Whether the Task inherits from CsvTask.
-
#deleted? ⇒ Boolean
private
Whether the Task has been deleted.
- #ensure_task_exists ⇒ self private
-
#initialize(name, runs_cursor: nil, arguments: nil) ⇒ TaskDataShow
constructor
private
Initializes a Task Data with a name.
-
#load_active_runs ⇒ self
private
Preloads the records from the active_runs ActiveRecord::Relation.
- #new ⇒ MaintenanceTasks::Task? private
-
#parameter_names ⇒ Array<String>
private
The names of parameters the Task accepts.
-
#refresh? ⇒ Boolean
private
Whether the task data needs to be refreshed.
Constructor Details
#initialize(name, runs_cursor: nil, arguments: nil) ⇒ 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.
19 20 21 22 23 |
# File 'app/models/maintenance_tasks/task_data_show.rb', line 19 def initialize(name, runs_cursor: nil, arguments: nil) @name = name @arguments = arguments @runs_page = RunsPage.new(completed_runs, runs_cursor) end |
Instance Attribute Details
#name ⇒ String (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.
40 41 42 |
# File 'app/models/maintenance_tasks/task_data_show.rb', line 40 def name @name end |
#runs_page ⇒ RunsPage (readonly)
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 current page of completed runs, based on the cursor passed in initialize.
45 46 47 |
# File 'app/models/maintenance_tasks/task_data_show.rb', line 45 def runs_page @runs_page end |
Class Method Details
.prepare(name, runs_cursor: nil, arguments: nil) ⇒ Object
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.
Prepares a Task Data from a task name.
32 33 34 35 36 |
# File 'app/models/maintenance_tasks/task_data_show.rb', line 32 def prepare(name, runs_cursor: nil, arguments: nil) new(name, runs_cursor:, arguments:) .load_active_runs .ensure_task_exists end |
Instance Method Details
#active_runs ⇒ ActiveRecord::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.
72 73 74 |
# File 'app/models/maintenance_tasks/task_data_show.rb', line 72 def active_runs @active_runs ||= runs.active end |
#code ⇒ 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.
The Task’s source code.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/maintenance_tasks/task_data_show.rb', line 51 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_runs ⇒ ActiveRecord::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.
83 84 85 |
# File 'app/models/maintenance_tasks/task_data_show.rb', line 83 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.
96 97 98 |
# File 'app/models/maintenance_tasks/task_data_show.rb', line 96 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.
88 89 90 91 92 93 |
# File 'app/models/maintenance_tasks/task_data_show.rb', line 88 def deleted? Task.named(name) false rescue Task::NotFoundError true end |
#ensure_task_exists ⇒ self
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.
132 133 134 135 136 137 |
# File 'app/models/maintenance_tasks/task_data_show.rb', line 132 def ensure_task_exists if active_runs.none? && runs_page.records.none? Task.named(name) end self end |
#load_active_runs ⇒ self
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.
Preloads the records from the active_runs ActiveRecord::Relation
125 126 127 128 |
# File 'app/models/maintenance_tasks/task_data_show.rb', line 125 def load_active_runs active_runs.load self end |
#new ⇒ MaintenanceTasks::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.
111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/models/maintenance_tasks/task_data_show.rb', line 111 def new return if deleted? task = MaintenanceTasks::Task.named(name).new begin task.assign_attributes(@arguments) if @arguments rescue ActiveModel::UnknownAttributeError # nothing to do end task end |
#parameter_names ⇒ Array<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.
101 102 103 104 105 106 107 |
# File 'app/models/maintenance_tasks/task_data_show.rb', line 101 def parameter_names if deleted? [] else Task.named(name).attribute_names end end |
#refresh? ⇒ 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 data needs to be refreshed.
64 65 66 |
# File 'app/models/maintenance_tasks/task_data_show.rb', line 64 def refresh? active_runs.any? end |