Class: Checkoff::MvSubcommand
- Inherits:
-
Object
- Object
- Checkoff::MvSubcommand
- Defined in:
- lib/checkoff/cli.rb,
sig/checkoff.rbs
Overview
Move tasks from one place to another
Instance Attribute Summary collapse
-
#from_project_name ⇒ Object
readonly
Returns the value of attribute from_project_name.
-
#from_section_name ⇒ Object
readonly
Returns the value of attribute from_section_name.
-
#from_workspace_name ⇒ Object
readonly
Returns the value of attribute from_workspace_name.
-
#projects ⇒ Object
readonly
Returns the value of attribute projects.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
-
#to_project_name ⇒ Object
readonly
Returns the value of attribute to_project_name.
-
#to_section_name ⇒ Object
readonly
Returns the value of attribute to_section_name.
-
#to_workspace_name ⇒ Object
readonly
Returns the value of attribute to_workspace_name.
Instance Method Summary collapse
-
#create_to_project_name(to_project_arg) ⇒ String, Symbol
@param
to_project_arg. -
#create_to_section_name(to_section_arg) ⇒ void
@param
to_section_arg— :source_section. -
#fetch_tasks(from_workspace_name, from_project_name, from_section_name) ⇒ ::Enumerable[Asana::Resources::Task]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
from_workspace_name. -
#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) ⇒ Object
constructor
@param
from_workspace_arg. -
#move_tasks(tasks, to_project, to_section) ⇒ void
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project @param
tasks. -
#project_arg_to_name(project_arg) ⇒ Symbol, String
@param
project_arg. - #run ⇒ void
-
#validate_and_assign_from_location(from_workspace_arg, from_project_arg, from_section_arg) ⇒ void
@param
from_workspace_arg. -
#validate_and_assign_to_location(to_workspace_arg, to_project_arg, to_section_arg) ⇒ void
@param
to_workspace_arg.
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) ⇒ Object
@param from_workspace_arg
@param from_project_arg
@param from_section_arg
@param to_workspace_arg
@param to_project_arg
@param to_section_arg — :source_section
@param config
@param projects
@param sections
@param logger
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/checkoff/cli.rb', line 86 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 Attribute Details
#from_project_name ⇒ Object (readonly)
Returns the value of attribute from_project_name.
86 87 88 |
# File 'sig/checkoff.rbs', line 86 def from_project_name @from_project_name end |
#from_section_name ⇒ Object (readonly)
Returns the value of attribute from_section_name.
89 90 91 |
# File 'sig/checkoff.rbs', line 89 def from_section_name @from_section_name end |
#from_workspace_name ⇒ Object (readonly)
Returns the value of attribute from_workspace_name.
83 84 85 |
# File 'sig/checkoff.rbs', line 83 def from_workspace_name @from_workspace_name end |
#projects ⇒ Object (readonly)
Returns the value of attribute projects.
101 102 103 |
# File 'sig/checkoff.rbs', line 101 def projects @projects end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
104 105 106 |
# File 'sig/checkoff.rbs', line 104 def sections @sections end |
#to_project_name ⇒ Object (readonly)
Returns the value of attribute to_project_name.
95 96 97 |
# File 'sig/checkoff.rbs', line 95 def to_project_name @to_project_name end |
#to_section_name ⇒ Object (readonly)
Returns the value of attribute to_section_name.
98 99 100 |
# File 'sig/checkoff.rbs', line 98 def to_section_name @to_section_name end |
#to_workspace_name ⇒ Object (readonly)
Returns the value of attribute to_workspace_name.
92 93 94 |
# File 'sig/checkoff.rbs', line 92 def to_workspace_name @to_workspace_name end |
Instance Method Details
#create_to_project_name(to_project_arg) ⇒ String, Symbol
@param to_project_arg
40 41 42 43 44 45 46 47 |
# File 'lib/checkoff/cli.rb', line 40 def create_to_project_name(to_project_arg) if to_project_arg == :source_project from_project_name else # @sg-ignore project_arg_to_name(to_project_arg) end end |
#create_to_section_name(to_section_arg) ⇒ void
This method returns an undefined value.
@param to_section_arg — :source_section
52 53 54 55 56 57 58 |
# File 'lib/checkoff/cli.rb', line 52 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]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param from_workspace_name
@param from_project_name
@param from_section_name
121 122 123 124 125 126 127 |
# File 'lib/checkoff/cli.rb', line 121 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.
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project
@param tasks
@param to_project
@param to_section
108 109 110 111 112 113 114 115 |
# File 'lib/checkoff/cli.rb', line 108 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 |
#project_arg_to_name(project_arg) ⇒ Symbol, String
@param project_arg
151 152 153 154 155 156 157 158 |
# File 'lib/checkoff/cli.rb', line 151 def project_arg_to_name(project_arg) arg = project_arg.to_s if arg.start_with?(':') arg.delete_prefix(':').to_sym else arg end end |
#run ⇒ void
This method returns an undefined value.
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/checkoff/cli.rb', line 130 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.
@param from_workspace_arg
@param from_project_arg
@param from_section_arg
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/checkoff/cli.rb', line 22 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 # @sg-ignore @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.
@param to_workspace_arg
@param to_project_arg
@param to_section_arg — :source_section
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/checkoff/cli.rb', line 64 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 |