checkoff 0.57.0 → 0.58.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '096eda83e243c4db30bcb92480b82f9be93dd9155b5fdb70058c4e364fe35c22'
4
- data.tar.gz: e2886085e543f652cf99c8f0784d2726a470e41f26434171afa3da3e43d84118
3
+ metadata.gz: e5b1efd75edc932f14b7c620a0c90ae36bb94a3734c1c6f8ee329301e6f50af8
4
+ data.tar.gz: 0fe857d53e21d4f66598104917c31fa455eeedc74f0e4e6aa6dc2a24f811c65a
5
5
  SHA512:
6
- metadata.gz: 6a119915c86c1124bc61aecb09bad54c3ec274feea2f4f627aadf24a090baae996a200361c4c5bfa52d9b8a65d822ca14b87b36fff4c486a9ee2f3763fc416a3
7
- data.tar.gz: 3596da35a48094243a44794df858acb0718141b40555c56889b6adf4ad16c47287633e1e5cbcd293385424e13aafc21ef640c6475933551370c9e6142facaee3
6
+ metadata.gz: 84b7f631a32dd256986d85fb132226075857339552f0b9b4a880cb17a0f0378e307d8a323beac840b7b2a0a62aad92283cc817dcad1622bf329462adbbfc619c
7
+ data.tar.gz: af485a9d86625ed4f138a2bc466e506686c9660af08178dba3f82750adad7a1d4f8379ba434707ef10f78b5f79134b1202843ab568ba1e1b26be213830f08a89
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.0)
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:
@@ -59,7 +59,7 @@ module Checkoff
59
59
  if project_name.is_a?(Symbol) && project_name.to_s.start_with?('my_tasks')
60
60
  my_tasks(workspace_name)
61
61
  else
62
- # @type [Asana::Collection<Asana::Resources::Project>]
62
+ # @type [Enumerable<Asana::Resources::Project>]
63
63
  ps = projects_by_workspace_name(workspace_name)
64
64
  ps.find do |project|
65
65
  project.name == project_name
@@ -102,6 +102,17 @@ module Checkoff
102
102
  end
103
103
  cache_method :tasks_from_project, SHORT_CACHE_TIME
104
104
 
105
+ # @param [String] workspace_name
106
+ # @param [Array<String>] extra_fields
107
+ # @return [Enumerable<Asana::Resources::Project>]
108
+ def projects_by_workspace_name(workspace_name, extra_fields: [])
109
+ workspace = @workspaces.workspace_or_raise(workspace_name)
110
+ options = { fields: %w[name] + extra_fields }
111
+ projects.find_by_workspace(workspace: workspace.gid, per_page: 100, options: options)
112
+ end
113
+ # 15 minute cache resulted in 'Your pagination token has expired'
114
+ cache_method :projects_by_workspace_name, MEDIUM_CACHE_TIME
115
+
105
116
  private
106
117
 
107
118
  # @return [Asana::Client]
@@ -113,17 +124,6 @@ module Checkoff
113
124
  end
114
125
  cache_method :projects, LONG_CACHE_TIME
115
126
 
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
127
  # @param [String] workspace_name
128
128
  # @return [Asana::Resources::Project]
129
129
  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.0'
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.0
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-09-30 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