checkoff 0.57.0 → 0.58.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '096eda83e243c4db30bcb92480b82f9be93dd9155b5fdb70058c4e364fe35c22'
4
- data.tar.gz: e2886085e543f652cf99c8f0784d2726a470e41f26434171afa3da3e43d84118
3
+ metadata.gz: a2b8e1f32a572bfcd4797199e3e8bf40a8bacfe3f20eb117a13f52e5f69feab5
4
+ data.tar.gz: fe61f004dcc81088a23acee2f2fe03c8cec9fc107d1850cc6450d6bde99bdbdc
5
5
  SHA512:
6
- metadata.gz: 6a119915c86c1124bc61aecb09bad54c3ec274feea2f4f627aadf24a090baae996a200361c4c5bfa52d9b8a65d822ca14b87b36fff4c486a9ee2f3763fc416a3
7
- data.tar.gz: 3596da35a48094243a44794df858acb0718141b40555c56889b6adf4ad16c47287633e1e5cbcd293385424e13aafc21ef640c6475933551370c9e6142facaee3
6
+ metadata.gz: 2e77e9c93328415564d60bc1b3b1ca29bb678ce425477137392acd26d92acd81823a9fa9e6db189ce2a22045ca6dc45df32a8548a9265889e95f86196d238b1e
7
+ data.tar.gz: 516063b25c108b17ac6039c3890cf375a623078b913a33fecb019ae4c9a4f76e2a1f3995fae4cb3c529d5dddcb2d9076f5ec07e940a464ed13330c5b63ab3fbd
data/Gemfile.lock CHANGED
@@ -12,7 +12,7 @@ GIT
12
12
  PATH
13
13
  remote: .
14
14
  specs:
15
- checkoff (0.57.0)
15
+ checkoff (0.58.1)
16
16
  activesupport
17
17
  asana (> 0.10.0)
18
18
  cache_method
@@ -45,7 +45,7 @@ GEM
45
45
  concurrent-ruby (1.2.2)
46
46
  crack (0.4.5)
47
47
  rexml
48
- dalli (3.2.5)
48
+ dalli (3.2.6)
49
49
  diff-lcs (1.5.0)
50
50
  docile (1.4.0)
51
51
  e2mmap (0.1.0)
@@ -139,7 +139,7 @@
139
139
  # #
140
140
  # # @param per_page [Integer] the number of records to fetch per page.
141
141
  # # @param options [Hash] the request I/O options.
142
- # # @return [Asana::Collection<Asana::Resources::Project>]
142
+ # # @return [Enumerable<Asana::Resources::Project>]
143
143
  # def find_by_workspace(client, workspace: required("workspace"), is_template: nil, archived: nil, per_page: 20, options: {}); end
144
144
  # # Returns the complete project record for a single project.
145
145
  # #
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'forwardable'
6
+ require 'cache_method'
7
+ require_relative 'internal/config_loader'
8
+ require_relative 'workspaces'
9
+ require_relative 'clients'
10
+
11
+ # https://developers.asana.com/docs/project-selectors
12
+
13
+ module Checkoff
14
+ # Filter lists of projects using declarative selectors.
15
+ class ProjectSelectors
16
+ MINUTE = 60
17
+ HOUR = MINUTE * 60
18
+ DAY = 24 * HOUR
19
+ REALLY_LONG_CACHE_TIME = HOUR * 1
20
+ LONG_CACHE_TIME = MINUTE * 15
21
+ SHORT_CACHE_TIME = MINUTE
22
+
23
+ # @param config [Hash<Symbol, Object>]
24
+ # @param workspaces [Checkoff::Workspaces]
25
+ # @param clients [Checkoff::Clients]
26
+ # @param client [Asana::Client]
27
+ def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana),
28
+ workspaces: Checkoff::Workspaces.new(config: config),
29
+ clients: Checkoff::Clients.new(config: config),
30
+ client: clients.client)
31
+ @workspaces = workspaces
32
+ @client = client
33
+ end
34
+
35
+ # @param [Asana::Resources::Project] project
36
+ # @param [Array<(Symbol, Array)>] project_selector Filter based on
37
+ # project details. Examples: [:tag, 'foo'] [:not, [:tag, 'foo']] [:tag, 'foo']
38
+ # @return [Boolean]
39
+ def filter_via_project_selector(project, project_selector)
40
+ if project_selector == [:custom_field_values_contain_any_value, 'Project attributes', ['timeline']]
41
+ custom_field = project.custom_fields.find { |field| field.fetch('name') == 'Project attributes' }
42
+
43
+ return false if custom_field.nil?
44
+
45
+ # @sg-ignore
46
+ # @type [Hash, nil]
47
+ timeline = custom_field.fetch('multi_enum_values').find do |multi_enum_value|
48
+ multi_enum_value.fetch('name') == 'timeline'
49
+ end
50
+
51
+ return !timeline.nil?
52
+ end
53
+
54
+ raise "Teach me how to evaluate #{project} against #{project_selector}"
55
+ end
56
+
57
+ private
58
+
59
+ # @return [Checkoff::Workspaces]
60
+ attr_reader :workspaces
61
+
62
+ # @return [Asana::Client]
63
+ attr_reader :client
64
+
65
+ # bundle exec ./project_selectors.rb
66
+ # :nocov:
67
+ class << self
68
+ # @return [void]
69
+ def run
70
+ # workspace_name = ARGV[0] || raise('Please pass workspace name as first argument')
71
+ # project_selector_name = ARGV[1] || raise('Please pass project_selector name as second argument')
72
+ # project_selectors = Checkoff::ProjectSelectors.new
73
+ # project_selector = project_selectors.project_selector_or_raise(workspace_name, project_selector_name)
74
+ # puts "Results: #{project_selector}"
75
+ end
76
+ end
77
+ # :nocov:
78
+ end
79
+ end
80
+
81
+ # :nocov:
82
+ abs_program_name = File.expand_path($PROGRAM_NAME)
83
+ Checkoff::ProjectSelectors.run if abs_program_name == File.expand_path(__FILE__)
84
+ # :nocov:
@@ -54,13 +54,14 @@ module Checkoff
54
54
  # pulls an Asana API project class given a name
55
55
  # @param [String] workspace_name
56
56
  # @param [String] project_name
57
+ # @param [Array<String>] extra_fields
57
58
  # @return [Asana::Resources::Project, nil]
58
- def project(workspace_name, project_name)
59
+ def project(workspace_name, project_name, extra_fields: [])
59
60
  if project_name.is_a?(Symbol) && project_name.to_s.start_with?('my_tasks')
60
61
  my_tasks(workspace_name)
61
62
  else
62
- # @type [Asana::Collection<Asana::Resources::Project>]
63
- ps = projects_by_workspace_name(workspace_name)
63
+ # @type [Enumerable<Asana::Resources::Project>]
64
+ ps = projects_by_workspace_name(workspace_name, extra_fields: extra_fields)
64
65
  ps.find do |project|
65
66
  project.name == project_name
66
67
  end
@@ -73,7 +74,7 @@ module Checkoff
73
74
  # @return [Asana::Resources::Project]
74
75
  def project_or_raise(workspace_name, project_name)
75
76
  p = project(workspace_name, project_name)
76
- raise "Could not find project #{project_name} under workspace #{workspace_name}." if p.nil?
77
+ raise "Could not find project #{project_name.inspect} under workspace #{workspace_name}." if p.nil?
77
78
 
78
79
  p
79
80
  end
@@ -102,6 +103,17 @@ module Checkoff
102
103
  end
103
104
  cache_method :tasks_from_project, SHORT_CACHE_TIME
104
105
 
106
+ # @param [String] workspace_name
107
+ # @param [Array<String>] extra_fields
108
+ # @return [Enumerable<Asana::Resources::Project>]
109
+ def projects_by_workspace_name(workspace_name, extra_fields: [])
110
+ workspace = @workspaces.workspace_or_raise(workspace_name)
111
+ options = { fields: %w[name] + extra_fields }
112
+ projects.find_by_workspace(workspace: workspace.gid, per_page: 100, options: options)
113
+ end
114
+ # 15 minute cache resulted in 'Your pagination token has expired'
115
+ cache_method :projects_by_workspace_name, MEDIUM_CACHE_TIME
116
+
105
117
  private
106
118
 
107
119
  # @return [Asana::Client]
@@ -113,17 +125,6 @@ module Checkoff
113
125
  end
114
126
  cache_method :projects, LONG_CACHE_TIME
115
127
 
116
- # @param [String] workspace_name
117
- # @return [Asana::Collection<Asana::Resources::Project>]
118
- def projects_by_workspace_name(workspace_name)
119
- workspace = @workspaces.workspace_or_raise(workspace_name)
120
- raise "Could not find workspace named #{workspace_name}" unless workspace
121
-
122
- projects.find_by_workspace(workspace: workspace.gid, per_page: 100)
123
- end
124
- # 15 minute cache resulted in 'Your pagination token has expired'
125
- cache_method :projects_by_workspace_name, MEDIUM_CACHE_TIME
126
-
127
128
  # @param [String] workspace_name
128
129
  # @return [Asana::Resources::Project]
129
130
  def my_tasks(workspace_name)
@@ -204,7 +204,7 @@ module Checkoff
204
204
 
205
205
  project = projects.project(workspace_name, project_name)
206
206
  if project.nil?
207
- raise "Could not find project #{project_name} " \
207
+ raise "Could not find project #{project_name.inspect} " \
208
208
  "under workspace #{workspace_name}"
209
209
  end
210
210
  project
@@ -3,5 +3,5 @@
3
3
  # Command-line and gem client for Asana (unofficial)
4
4
  module Checkoff
5
5
  # Version of library
6
- VERSION = '0.57.0'
6
+ VERSION = '0.58.1'
7
7
  end
data/lib/checkoff.rb CHANGED
@@ -10,4 +10,5 @@ require 'checkoff/tasks'
10
10
  require 'checkoff/custom_fields'
11
11
  require 'checkoff/tags'
12
12
  require 'checkoff/task_selectors'
13
+ require 'checkoff/project_selectors'
13
14
  require 'checkoff/task_searches'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checkoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.57.0
4
+ version: 0.58.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vince Broz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-18 00:00:00.000000000 Z
11
+ date: 2023-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -141,6 +141,7 @@ files:
141
141
  - lib/checkoff/internal/search_url/simple_param_converter.rb
142
142
  - lib/checkoff/internal/task_selector_evaluator.rb
143
143
  - lib/checkoff/my_tasks.rb
144
+ - lib/checkoff/project_selectors.rb
144
145
  - lib/checkoff/projects.rb
145
146
  - lib/checkoff/sections.rb
146
147
  - lib/checkoff/subtasks.rb