Class: Checkoff::Subtasks

Inherits:
Object
  • Object
show all
Extended by:
CacheMethod::ClassMethods, Forwardable
Defined in:
lib/checkoff/subtasks.rb,
sig/checkoff.rbs

Overview

Query different subtasks of Asana tasks

Constant Summary collapse

MINUTE =

Returns:

  • (Object)
60
LONG_CACHE_TIME =

Returns:

  • (Object)
MINUTE * 15
SHORT_CACHE_TIME =

Returns:

  • (Object)
MINUTE * 5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config:), clients: Checkoff::Clients.new(config:)) ⇒ Subtasks

@param config

@param projects

@param clients

Parameters:



23
24
25
26
27
28
# File 'lib/checkoff/subtasks.rb', line 23

def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana),
               projects: Checkoff::Projects.new(config:),
               clients: Checkoff::Clients.new(config:))
  @projects = projects
  @client = clients.client
end

Instance Attribute Details

#clientAsana::Client (readonly)

sord warn - Asana::Client wasn't able to be resolved to a constant in this project

Returns:

  • (Asana::Client)


103
104
105
# File 'lib/checkoff/subtasks.rb', line 103

def client
  @client
end

#projectsCheckoff::Projects (readonly)

Returns:



100
101
102
# File 'lib/checkoff/subtasks.rb', line 100

def projects
  @projects
end

Instance Method Details

#all_subtasks_completed?(task) ⇒ Boolean

sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project True if all subtasks of the task are completed

@param task

Parameters:

  • task (Asana::Resources::Task)

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'lib/checkoff/subtasks.rb', line 33

def all_subtasks_completed?(task)
  rs = raw_subtasks(task)
  active_subtasks = @projects.active_tasks(rs)
  # anything left should be a section
  active_subtasks.all? { |subtask| subtask_section?(subtask) }
end

#by_section(tasks) ⇒ ::Hash[String?, ::Enumerable[Asana::Resources::Task]]

sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project pulls a Hash of subtasks broken out by section

@param tasks

Parameters:

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

Returns:

  • (::Hash[String?, ::Enumerable[Asana::Resources::Task]])


45
46
47
48
49
50
51
52
53
# File 'lib/checkoff/subtasks.rb', line 45

def by_section(tasks)
  current_section = nil
  by_section = { nil => [] }
  tasks.each do |task|
    current_section, by_section = file_task_by_section(current_section,
                                                       by_section, task)
  end
  by_section
end

#file_task_by_section(current_section, by_section, task) ⇒ [String, ::Hash[untyped, untyped]]

sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param current_section

@param by_section

@param task

Parameters:

  • current_section (String, nil)
  • by_section (::Hash[untyped, untyped])
  • task (Asana::Resources::Task)

Returns:

  • ([String, ::Hash[untyped, untyped]])


110
111
112
113
114
115
116
117
118
119
120
# File 'lib/checkoff/subtasks.rb', line 110

def file_task_by_section(current_section, by_section, task)
  if subtask_section?(task)
    current_section = task.name
    raise "More than one section named #{task.name}" if by_section.key? task.name

    by_section[current_section] = []
  else
    by_section[current_section] << task
  end
  [current_section, by_section]
end

#raw_subtasks(task) ⇒ ::Enumerable[Asana::Resources::Task]

sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Returns all subtasks, including section headers

@param task

Parameters:

  • task (Asana::Resources::Task)

Returns:

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


60
61
62
# File 'lib/checkoff/subtasks.rb', line 60

def raw_subtasks(task)
  subtasks_by_gid(task.gid)
end

#subtask_section?(subtask) ⇒ Boolean

sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project True if the subtask passed in represents a section in the subtasks

Note: expect this to be removed in a future version, as Asana is expected to move to the new-style way of representing sections as memberships with a separate API within a task.

@sg-ignore

@param subtask

Parameters:

  • subtask (Asana::Resources::Task)

Returns:

  • (Boolean)


93
94
95
# File 'lib/checkoff/subtasks.rb', line 93

def subtask_section?(subtask)
  subtask.is_rendered_as_separator
end

#subtasks_by_gid(task_gid, extra_fields: [], only_uncompleted: true) ⇒ ::Enumerable[Asana::Resources::Task]

sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Pull a specific task by GID

@param task_gid

@param extra_fields

@param only_uncompleted

Parameters:

  • task_gid (String)
  • extra_fields: (::Array[String]) (defaults to: [])
  • only_uncompleted: (Boolean) (defaults to: true)

Returns:

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


72
73
74
75
76
77
78
79
80
81
82
# File 'lib/checkoff/subtasks.rb', line 72

def subtasks_by_gid(task_gid,
                    extra_fields: [],
                    only_uncompleted: true)
  # @type [Hash]
  all_options = projects.task_options(extra_fields: extra_fields + %w[is_rendered_as_separator],
                                      only_uncompleted:)
  options = all_options.fetch(:options, {})
  client.tasks.get_subtasks_for_task(task_gid:,
                                     # per_page: 100, # stub doesn't have this arg available
                                     options:)
end