Class: Checkoff::ViewSubcommand
- Inherits:
-
Object
- Object
- Checkoff::ViewSubcommand
- Defined in:
- lib/checkoff/cli.rb,
sig/checkoff.rbs
Overview
CLI subcommand that shows tasks in JSON form
Instance Attribute Summary collapse
-
#project_name ⇒ Object
readonly
Returns the value of attribute project_name.
-
#section_name ⇒ Object
readonly
Returns the value of attribute section_name.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#task_name ⇒ Object
readonly
Returns the value of attribute task_name.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
-
#workspace_name ⇒ Object
readonly
Returns the value of attribute workspace_name.
Instance Method Summary collapse
-
#initialize(workspace_name, project_name, section_name, task_name, config: Checkoff::Internal::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config:), sections: Checkoff::Sections.new(config:, projects:), tasks: Checkoff::Tasks.new(config:, sections:), stderr: $stderr) ⇒ Object
constructor
@param
workspace_name. - #run ⇒ void
-
#run_on_project(workspace, project) ⇒ String
@param
workspace. -
#run_on_section(workspace, project, section) ⇒ String
@param
workspace. -
#run_on_task(workspace, project, section, task_name) ⇒ Object
@param
workspace. -
#task_to_hash(task) ⇒ ::Hash[Symbol, untyped]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
task. -
#tasks_to_hash(tasks) ⇒ ::Array[::Hash[untyped, untyped]]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
tasks. -
#validate_and_assign_project_name(project_name) ⇒ String, Symbol
@param
project_name.
Constructor Details
#initialize(workspace_name, project_name, section_name, task_name, config: Checkoff::Internal::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config:), sections: Checkoff::Sections.new(config:, projects:), tasks: Checkoff::Tasks.new(config:, sections:), stderr: $stderr) ⇒ Object
@param workspace_name
@param project_name
@param section_name
@param task_name
@param config
@param projects
@param sections
@param tasks
@param stderr
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/checkoff/cli.rb', line 172 def initialize(workspace_name, project_name, section_name, task_name, config: Checkoff::Internal::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config:), sections: Checkoff::Sections.new(config:, projects:), tasks: Checkoff::Tasks.new(config:, sections:), stderr: $stderr) @workspace_name = workspace_name @stderr = stderr validate_and_assign_project_name(project_name) @section_name = section_name @task_name = task_name @sections = sections @tasks = tasks end |
Instance Attribute Details
#project_name ⇒ Object (readonly)
Returns the value of attribute project_name.
181 182 183 |
# File 'sig/checkoff.rbs', line 181 def project_name @project_name end |
#section_name ⇒ Object (readonly)
Returns the value of attribute section_name.
184 185 186 |
# File 'sig/checkoff.rbs', line 184 def section_name @section_name end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
190 191 192 |
# File 'sig/checkoff.rbs', line 190 def sections @sections end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
196 197 198 |
# File 'sig/checkoff.rbs', line 196 def stderr @stderr end |
#task_name ⇒ Object (readonly)
Returns the value of attribute task_name.
187 188 189 |
# File 'sig/checkoff.rbs', line 187 def task_name @task_name end |
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
193 194 195 |
# File 'sig/checkoff.rbs', line 193 def tasks @tasks end |
#workspace_name ⇒ Object (readonly)
Returns the value of attribute workspace_name.
178 179 180 |
# File 'sig/checkoff.rbs', line 178 def workspace_name @workspace_name end |
Instance Method Details
#run ⇒ void
This method returns an undefined value.
191 192 193 194 195 196 197 198 199 200 |
# File 'lib/checkoff/cli.rb', line 191 def run if section_name.nil? run_on_project(workspace_name, project_name) elsif task_name.nil? run_on_section(workspace_name, project_name, section_name) else # @sg-ignore run_on_task(workspace_name, project_name, section_name, task_name) end end |
#run_on_project(workspace, project) ⇒ String
@param workspace
@param project
219 220 221 222 223 224 225 226 227 |
# File 'lib/checkoff/cli.rb', line 219 def run_on_project(workspace, project) tasks_by_section = # @sg-ignore sections.tasks_by_section(workspace, project) tasks_by_section.update(tasks_by_section) do |_key, tasks| tasks_to_hash(tasks) end tasks_by_section.to_json end |
#run_on_section(workspace, project, section) ⇒ String
@param workspace
@param project
@param section
233 234 235 236 237 |
# File 'lib/checkoff/cli.rb', line 233 def run_on_section(workspace, project, section) section = nil if section == '' tasks = sections.tasks(workspace, project, section) || [] tasks_to_hash(tasks).to_json end |
#run_on_task(workspace, project, section, task_name) ⇒ Object
@param workspace
@param project
@param section
@param task_name
244 245 246 247 248 249 250 251 |
# File 'lib/checkoff/cli.rb', line 244 def run_on_task(workspace, project, section, task_name) section = nil if section == '' task = tasks.task(workspace.to_s, project, task_name, section_name: section) raise "Task not found: #{task_name}" if task.nil? # @sg-ignore nil check above is not flow-sensitive task_to_hash(task).to_json end |
#task_to_hash(task) ⇒ ::Hash[Symbol, untyped]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param task
255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/checkoff/cli.rb', line 255 def task_to_hash(task) task_out = { name: task.name, } if task.due_on task_out[:due] = task.due_on elsif task.due_at task_out[:due] = task.due_at end task_out end |
#tasks_to_hash(tasks) ⇒ ::Array[::Hash[untyped, untyped]]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param tasks
269 270 271 |
# File 'lib/checkoff/cli.rb', line 269 def tasks_to_hash(tasks) tasks.map { |task| task_to_hash(task) } end |
#validate_and_assign_project_name(project_name) ⇒ String, Symbol
@param project_name
206 207 208 209 210 211 212 213 |
# File 'lib/checkoff/cli.rb', line 206 def validate_and_assign_project_name(project_name) name = project_name.to_s @project_name = if name.start_with?(':') name.delete_prefix(':').to_sym else name end end |