class Checkoff::MvSubcommand

Move tasks from one place to another

Attributes

from_project_name[R]
from_section_name[R]
from_workspace_name[R]
projects[R]
sections[R]
to_project_name[R]
to_section_name[R]
to_workspace_name[R]

Public Class Methods

new(from_workspace_arg:, from_project_arg:, from_section_arg:, to_workspace_arg:, to_project_arg:, to_section_arg:, config: Checkoff::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config: config), sections: Checkoff::Sections.new(config: config), logger: $stderr) click to toggle source
# File lib/checkoff/cli.rb, line 58
def initialize(from_workspace_arg:,
               from_project_arg:,
               from_section_arg:,
               to_workspace_arg:,
               to_project_arg:,
               to_section_arg:,
               config: Checkoff::ConfigLoader.load(:asana),
               projects: Checkoff::Projects.new(config: config),
               sections: Checkoff::Sections.new(config: config),
               logger: $stderr)
  validate_and_assign_from_location(from_workspace_arg, from_project_arg, from_section_arg)
  validate_and_assign_to_location(to_workspace_arg, to_project_arg, to_section_arg)

  @projects = projects
  @sections = sections
  @logger = logger
end

Public Instance Methods

create_to_project_name(to_project_arg) click to toggle source
# File lib/checkoff/cli.rb, line 31
def create_to_project_name(to_project_arg)
  if to_project_arg == :source_project
    from_project_name
  else
    project_arg_to_name(to_project_arg)
  end
end
create_to_section_name(to_section_arg) click to toggle source
# File lib/checkoff/cli.rb, line 39
def create_to_section_name(to_section_arg)
  if to_section_arg == :source_section
    from_section_name
  else
    to_section_arg
  end
end
fetch_tasks(from_workspace_name, from_project_name, from_section_name) click to toggle source
# File lib/checkoff/cli.rb, line 85
def fetch_tasks(from_workspace_name, from_project_name, from_section_name)
  if from_section_name == :all_sections
    raise NotImplementedError, 'Not implemented: Teach me how to move all sections of a project'
  end

  sections.tasks(from_workspace_name, from_project_name, from_section_name)
end
move_tasks(tasks, to_project, to_section) click to toggle source
# File lib/checkoff/cli.rb, line 76
def move_tasks(tasks, to_project, to_section)
  tasks.each do |task|
    # a. check if already in correct project and section (TODO)
    # b. if not, put it there
    @logger.puts "Moving #{task.name} to #{to_section.name}..."
    task.add_project(project: to_project.gid, section: to_section.gid)
  end
end
run() click to toggle source
# File lib/checkoff/cli.rb, line 93
def run
  # 0. Look up project and section gids
  to_project = projects.project_or_raise(to_workspace_name, to_project_name)
  to_section = sections.section_or_raise(to_workspace_name, to_project_name, to_section_name)

  # 1. Get list of tasks which match
  tasks = fetch_tasks(from_workspace_name, from_project_name, from_section_name)
  # 2. for each task,
  move_tasks(tasks, to_project, to_section)
  # 3. tell the user we're done'
  @logger.puts 'Done moving tasks'
end
validate_and_assign_from_location(from_workspace_arg, from_project_arg, from_section_arg) click to toggle source
# File lib/checkoff/cli.rb, line 17
def validate_and_assign_from_location(from_workspace_arg, from_project_arg, from_section_arg)
  if from_workspace_arg == :default_workspace
    # Figure out what to do here - we accept a default
    # workspace gid and default workspace_gid arguments elsewhere.
    # however, there are undefaulted workspace_name arguments as
    # well...
    raise NotImplementedError, 'Not implemented: Teach me how to look up default workspace name'
  end

  @from_workspace_name = from_workspace_arg
  @from_project_name = project_arg_to_name(from_project_arg)
  @from_section_name = from_section_arg
end
validate_and_assign_to_location(to_workspace_arg, to_project_arg, to_section_arg) click to toggle source
# File lib/checkoff/cli.rb, line 47
def validate_and_assign_to_location(to_workspace_arg, to_project_arg, to_section_arg)
  @to_workspace_name = to_workspace_arg
  @to_workspace_name = from_workspace_name if to_workspace_arg == :source_workspace
  @to_project_name = create_to_project_name(to_project_arg)
  @to_section_name = create_to_section_name(to_section_arg)

  return unless from_workspace_name != to_workspace_name

  raise NotImplementedError, 'Not implemented: Teach me how to move tasks between workspaces'
end

Private Instance Methods

project_arg_to_name(project_arg) click to toggle source
# File lib/checkoff/cli.rb, line 112
def project_arg_to_name(project_arg)
  if project_arg.start_with? ':'
    project_arg[1..].to_sym
  else
    project_arg
  end
end