Class: Checkoff::MvSubcommand

Inherits:
Object
  • Object
show all
Defined in:
lib/checkoff/cli.rb,
sig/checkoff.rbs

Overview

Move tasks from one place to another

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (readonly)

Returns the value of attribute from_project_name.

Returns:

  • (Object)


86
87
88
# File 'sig/checkoff.rbs', line 86

def from_project_name
  @from_project_name
end

#from_section_nameObject (readonly)

Returns the value of attribute from_section_name.

Returns:

  • (Object)


89
90
91
# File 'sig/checkoff.rbs', line 89

def from_section_name
  @from_section_name
end

#from_workspace_nameObject (readonly)

Returns the value of attribute from_workspace_name.

Returns:

  • (Object)


83
84
85
# File 'sig/checkoff.rbs', line 83

def from_workspace_name
  @from_workspace_name
end

#projectsObject (readonly)

Returns the value of attribute projects.

Returns:

  • (Object)


101
102
103
# File 'sig/checkoff.rbs', line 101

def projects
  @projects
end

#sectionsObject (readonly)

Returns the value of attribute sections.

Returns:

  • (Object)


104
105
106
# File 'sig/checkoff.rbs', line 104

def sections
  @sections
end

#to_project_nameObject (readonly)

Returns the value of attribute to_project_name.

Returns:

  • (Object)


95
96
97
# File 'sig/checkoff.rbs', line 95

def to_project_name
  @to_project_name
end

#to_section_nameObject (readonly)

Returns the value of attribute to_section_name.

Returns:

  • (Object)


98
99
100
# File 'sig/checkoff.rbs', line 98

def to_section_name
  @to_section_name
end

#to_workspace_nameObject (readonly)

Returns the value of attribute to_workspace_name.

Returns:

  • (Object)


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

Parameters:

  • to_project_arg (Symbol, String)

Returns:

  • (String, Symbol)


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

Parameters:

  • to_section_arg (Symbol, String, nil)


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

Parameters:

  • from_workspace_name (String, Symbol)
  • from_project_name (String, Symbol)
  • from_section_name (String, Symbol, nil)

Returns:

  • (::Enumerable[Asana::Resources::Task])


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

Parameters:

  • tasks (::Enumerable[Asana::Resources::Task])
  • to_project (Asana::Resources::Project)
  • to_section (Asana::Resources::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

Parameters:

  • project_arg (String)

Returns:

  • (Symbol, String)


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

#runvoid

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

Parameters:

  • from_workspace_arg (Symbol, String)
  • from_project_arg (Symbol, String)
  • from_section_arg (String, nil)


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

Parameters:

  • to_workspace_arg (Symbol, String)
  • to_project_arg (Symbol, String)
  • to_section_arg (Symbol, String, nil)


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