Class: Checkoff::Timelines
- Inherits:
-
Object
- Object
- Checkoff::Timelines
- Extended by:
- CacheMethod::ClassMethods
- Defined in:
- lib/checkoff/timelines.rb,
sig/checkoff.rbs
Overview
Manages timelines of dependent tasks with dates and milestones
Constant Summary collapse
- MINUTE =
60- HOUR =
MINUTE * 60
- DAY =
24 * HOUR
- REALLY_LONG_CACHE_TIME =
HOUR- LONG_CACHE_TIME =
MINUTE * 15
- SHORT_CACHE_TIME =
MINUTE
Instance Attribute Summary collapse
-
#client ⇒ Asana::Client
readonly
sord warn - Asana::Client wasn't able to be resolved to a constant in this project.
- #workspaces ⇒ Checkoff::Workspaces readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#any_milestone_depends_on_this_task?(task, limit_to_portfolio_name: nil) ⇒ Boolean
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
task. -
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config:), sections: Checkoff::Sections.new(config:), tasks: Checkoff::Tasks.new(config:), portfolios: Checkoff::Portfolios.new(config:), clients: Checkoff::Clients.new(config:), client: clients.client) ⇒ Object
constructor
sord warn - Asana::Client wasn't able to be resolved to a constant in this project @param
config. -
#last_milestone_in_section(section_gid) ⇒ Asana::Resources::Task?
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
section_gid. -
#last_task_milestone_depends_on_this_task?(task, limit_to_portfolio_name: nil) ⇒ Boolean
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
task. -
#task_data_dependent_on_previous_section_last_milestone?(task_data, section) ⇒ Boolean
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project @param
task_data. -
#task_dependent_on_previous_section_last_milestone?(task, limit_to_portfolio_gid: nil) ⇒ Boolean
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
task.
Constructor Details
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config:), sections: Checkoff::Sections.new(config:), tasks: Checkoff::Tasks.new(config:), portfolios: Checkoff::Portfolios.new(config:), clients: Checkoff::Clients.new(config:), client: clients.client) ⇒ Object
sord warn - Asana::Client wasn't able to be resolved to a constant in this project
@param config
@param workspaces
@param sections
@param tasks
@param portfolios
@param clients
@param client
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/checkoff/timelines.rb', line 34 def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config:), sections: Checkoff::Sections.new(config:), tasks: Checkoff::Tasks.new(config:), portfolios: Checkoff::Portfolios.new(config:), clients: Checkoff::Clients.new(config:), client: clients.client) @workspaces = workspaces @sections = sections @tasks = tasks @portfolios = portfolios @client = client end |
Instance Attribute Details
#client ⇒ Asana::Client (readonly)
sord warn - Asana::Client wasn't able to be resolved to a constant in this project
177 178 179 |
# File 'lib/checkoff/timelines.rb', line 177 def client @client end |
#workspaces ⇒ Checkoff::Workspaces (readonly)
174 175 176 |
# File 'lib/checkoff/timelines.rb', line 174 def workspaces @workspaces end |
Class Method Details
.run ⇒ void
This method returns an undefined value.
183 184 185 186 187 188 189 190 191 |
# File 'lib/checkoff/timelines.rb', line 183 def run # @type [String] # workspace_name = ARGV[0] || raise('Please pass workspace name as first argument') # @type [String] # timeline_name = ARGV[1] || raise('Please pass timeline name as second argument') # timelines = Checkoff::Timelines.new # timeline = timelines.timeline_or_raise(workspace_name, timeline_name) # puts "Results: #{timeline}" end |
Instance Method Details
#any_milestone_depends_on_this_task?(task, limit_to_portfolio_name: nil) ⇒ Boolean
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param task
@param limit_to_portfolio_name
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/checkoff/timelines.rb', line 106 def any_milestone_depends_on_this_task?(task, limit_to_portfolio_name: nil) unless limit_to_portfolio_name.nil? limit_to_projects = @portfolios.projects_in_portfolio(T.must(@workspaces.default_workspace.name), limit_to_portfolio_name) end all_dependent_milestones = nil # @type [Array<Hash{String => Object}>] memberships = task.memberships memberships.all? do |membership_data| # @type [Hash{String => Object}] md = membership_data unless limit_to_portfolio_name.nil? # @type [Hash{String => Object}] project_data = md.fetch('project') project_gid = project_data.fetch('gid') next true unless limit_to_projects.map(&:gid).include? project_gid end # do this once, but lazily, so we don't have to do it if all # projects are excluded all_dependent_milestones ||= @tasks.all_dependent_tasks(task, extra_task_fields: ['resource_subtype', 'memberships.project.gid']).select do |dependent_task| dependent_task.resource_subtype == 'milestone' end all_dependent_milestones.any? do |milestone| milestone.memberships.any? do |milestone_membership_data| milestone_membership_data.fetch('project').fetch('gid') == project_gid end end end end |
#last_milestone_in_section(section_gid) ⇒ Asana::Resources::Task?
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param section_gid
145 146 147 148 149 150 151 |
# File 'lib/checkoff/timelines.rb', line 145 def last_milestone_in_section(section_gid) # @type [Array<Asana::Resources::Task>] task_list = @sections.tasks_by_section_gid(section_gid, extra_fields: ['resource_subtype']).to_a last_task = task_list.last last_task&.resource_subtype == 'milestone' ? last_task : nil end |
#last_task_milestone_depends_on_this_task?(task, limit_to_portfolio_name: nil) ⇒ Boolean
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param task
@param limit_to_portfolio_name
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/checkoff/timelines.rb', line 69 def last_task_milestone_depends_on_this_task?(task, limit_to_portfolio_name: nil) unless limit_to_portfolio_name.nil? limit_to_projects = @portfolios.projects_in_portfolio(T.must(@workspaces.default_workspace.name), limit_to_portfolio_name) end all_dependent_task_gids = nil # @type [Array<Hash{String => Object}>] memberships = task.memberships memberships.all? do |membership_data| # @type [Hash{String => Object}] md = membership_data unless limit_to_portfolio_name.nil? # @type [Hash{String => Object}] project_data = md.fetch('project') project_gid = project_data.fetch('gid') next true unless limit_to_projects.map(&:gid).include? project_gid end # @type [Hash{String => Object}] section_data = md.fetch('section') section_gid = section_data.fetch('gid') last_milestone = last_milestone_in_section(section_gid) next false if last_milestone.nil? next true if last_milestone.gid == task.gid all_dependent_task_gids ||= @tasks.all_dependent_tasks(task).map(&:gid) all_dependent_task_gids.include? last_milestone.gid end end |
#task_data_dependent_on_previous_section_last_milestone?(task_data, section) ⇒ Boolean
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project
@param task_data
@param section
159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/checkoff/timelines.rb', line 159 def task_data_dependent_on_previous_section_last_milestone?(task_data, section) previous_section = @sections.previous_section(section) return false if previous_section.nil? previous_section_last_milestone = last_milestone_in_section(previous_section.gid) return true if previous_section_last_milestone.nil? # @type [Array<Hash{String => String}>] dependencies = task_data.fetch('dependencies') return false if dependencies.empty? dependencies.any? { |dependency| dependency.fetch('gid') == previous_section_last_milestone.gid } end |
#task_dependent_on_previous_section_last_milestone?(task, limit_to_portfolio_gid: nil) ⇒ Boolean
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param task
@param limit_to_portfolio_gid
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/checkoff/timelines.rb', line 51 def task_dependent_on_previous_section_last_milestone?(task, limit_to_portfolio_gid: nil) task_data = @tasks.task_to_h(task) # @type [Array<Hash{String => Hash{String => String}}>] memberships_data = task_data.fetch('memberships') memberships_data.all? do |membership_data| # @type [Hash{String => String}] section_data = membership_data.fetch('section') section_gid = section_data.fetch('gid') section = @sections.section_by_gid(section_gid) next false if section.nil? task_data_dependent_on_previous_section_last_milestone?(task_data, section) end end |