class Checkoff::ViewSubcommand
CLI subcommand that shows tasks in JSON form
Attributes
project_name[R]
section_name[R]
sections[R]
stderr[R]
task_name[R]
tasks[R]
workspace_name[R]
Public Class Methods
new(workspace_name, project_name, section_name, task_name, config: Checkoff::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config: config), sections: Checkoff::Sections.new(config: config, projects: projects), tasks: Checkoff::Tasks.new(config: config, sections: sections), stderr: $stderr)
click to toggle source
# File lib/checkoff/cli.rb, line 123 def initialize(workspace_name, project_name, section_name, task_name, config: Checkoff::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config: config), sections: Checkoff::Sections.new(config: config, projects: projects), tasks: Checkoff::Tasks.new(config: config, sections: 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
Public Instance Methods
run()
click to toggle source
# File lib/checkoff/cli.rb, line 141 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 run_on_task(workspace_name, project_name, section_name, task_name) end end
Private Instance Methods
run_on_project(workspace, project)
click to toggle source
# File lib/checkoff/cli.rb, line 161 def run_on_project(workspace, project) tasks_by_section = 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)
click to toggle source
# File lib/checkoff/cli.rb, line 170 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)
click to toggle source
# File lib/checkoff/cli.rb, line 176 def run_on_task(workspace, project, section, task_name) section = nil if section == '' task = tasks.task(workspace, project, task_name, section_name: section) task_to_hash(task).to_json end
task_to_hash(task)
click to toggle source
# File lib/checkoff/cli.rb, line 182 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)
click to toggle source
# File lib/checkoff/cli.rb, line 194 def tasks_to_hash(tasks) tasks.map { |task| task_to_hash(task) } end
validate_and_assign_project_name(project_name)
click to toggle source
# File lib/checkoff/cli.rb, line 153 def validate_and_assign_project_name(project_name) @project_name = if project_name.start_with? ':' project_name[1..].to_sym else project_name end end