Class: Checkoff::MvSubcommand
- Inherits:
-
Object
- Object
- Checkoff::MvSubcommand
- Defined in:
- lib/checkoff/cli.rb
Overview
Move tasks from one place to another
Instance Method Summary collapse
- #create_to_project_name(to_project_arg) ⇒ String, Symbol
- #create_to_section_name(to_section_arg) ⇒ nil, ...
- #fetch_tasks(from_workspace_name, from_project_name, from_section_name) ⇒ Enumerable<Asana::Resources::Task>
- #initialize(from_workspace_arg:, from_project_arg:, from_section_arg:, to_workspace_arg:, to_project_arg:, to_section_arg:, config: Checkoff::Internal::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config:), sections: Checkoff::Sections.new(config:), logger: $stderr) ⇒ void constructor
- #move_tasks(tasks, to_project, to_section) ⇒ void
- #run ⇒ void
- #validate_and_assign_from_location(from_workspace_arg, from_project_arg, from_section_arg) ⇒ void
- #validate_and_assign_to_location(to_workspace_arg, to_project_arg, to_section_arg) ⇒ void
Constructor Details
#initialize(from_workspace_arg:, from_project_arg:, from_section_arg:, to_workspace_arg:, to_project_arg:, to_section_arg:, config: Checkoff::Internal::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config:), sections: Checkoff::Sections.new(config:), logger: $stderr) ⇒ void
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/checkoff/cli.rb', line 83 def initialize(from_workspace_arg:, from_project_arg:, from_section_arg:, to_workspace_arg:, to_project_arg:, to_section_arg:, config: Checkoff::Internal::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config:), sections: Checkoff::Sections.new(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 |
Instance Method Details
#create_to_project_name(to_project_arg) ⇒ String, Symbol
38 39 40 41 42 43 44 |
# File 'lib/checkoff/cli.rb', line 38 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) ⇒ nil, ...
49 50 51 52 53 54 55 |
# File 'lib/checkoff/cli.rb', line 49 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) ⇒ Enumerable<Asana::Resources::Task>
118 119 120 121 122 123 124 |
# File 'lib/checkoff/cli.rb', line 118 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) ⇒ void
This method returns an undefined value.
105 106 107 108 109 110 111 112 |
# File 'lib/checkoff/cli.rb', line 105 def move_tasks(tasks, to_project, to_section) tasks.each do |task| # a. check if already in correct project and section (future) # 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 ⇒ void
This method returns an undefined value.
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/checkoff/cli.rb', line 127 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) ⇒ void
This method returns an undefined value.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/checkoff/cli.rb', line 21 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) ⇒ void
This method returns an undefined value.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/checkoff/cli.rb', line 61 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 |