Class: Checkoff::Subtasks

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

Overview

Query different subtasks of Asana tasks

Constant Summary collapse

MINUTE =
60
LONG_CACHE_TIME =
MINUTE * 15
SHORT_CACHE_TIME =
MINUTE * 5

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Subtasks.

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 Method Details

#all_subtasks_completed?(task) ⇒ Boolean

True if all subtasks of the task are completed

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{nil,String => Enumerable<Asana::Resources::Task>}

pulls a Hash of subtasks broken out by section

Parameters:

  • tasks (Enumerable<Asana::Resources::Task>)

Returns:

  • (Hash{nil,String => Enumerable<Asana::Resources::Task>})


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

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

#raw_subtasks(task) ⇒ Enumerable<Asana::Resources::Task>

Returns all subtasks, including section headers

Parameters:

  • task (Asana::Resources::Task)

Returns:

  • (Enumerable<Asana::Resources::Task>)


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

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

#subtask_section?(subtask) ⇒ Boolean

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.

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>

Pull a specific task by GID

Parameters:

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

Returns:

  • (Enumerable<Asana::Resources::Task>)


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

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