Class: Checkoff::Subtasks
- Inherits:
-
Object
- Object
- Checkoff::Subtasks
- 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
-
#all_subtasks_completed?(task) ⇒ Boolean
True if all subtasks of the task are completed.
-
#by_section(tasks) ⇒ Hash<[nil,String], Enumerable<Asana::Resources::Task>>
pulls a Hash of subtasks broken out by section.
-
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config: config), clients: Checkoff::Clients.new(config: config)) ⇒ Subtasks
constructor
A new instance of Subtasks.
-
#raw_subtasks(task) ⇒ Enumerable<Asana::Resources::Task>
Returns all subtasks, including section headers.
-
#subtask_section?(subtask) ⇒ Boolean
True if the subtask passed in represents a section in the subtasks.
-
#subtasks_by_gid(task_gid, extra_fields: [], only_uncompleted: true) ⇒ Enumerable<Asana::Resources::Task>
Pull a specific task by GID.
Constructor Details
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config: config), clients: Checkoff::Clients.new(config: config)) ⇒ Subtasks
Returns a new instance of Subtasks.
22 23 24 25 26 27 |
# File 'lib/checkoff/subtasks.rb', line 22 def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config: config), clients: Checkoff::Clients.new(config: config)) @projects = projects @client = clients.client end |
Instance Method Details
#all_subtasks_completed?(task) ⇒ Boolean
True if all subtasks of the task are completed
32 33 34 35 36 37 |
# File 'lib/checkoff/subtasks.rb', line 32 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
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/checkoff/subtasks.rb', line 44 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
60 61 62 |
# File 'lib/checkoff/subtasks.rb', line 60 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.
92 93 94 |
# File 'lib/checkoff/subtasks.rb', line 92 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
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] = projects.(extra_fields: extra_fields + %w[is_rendered_as_separator], only_uncompleted: only_uncompleted) = .fetch(:options, {}) client.tasks.get_subtasks_for_task(task_gid: task_gid, # per_page: 100, # stub doesn't have this arg available options: ) end |