checkoff 0.109.0 → 0.110.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: 199142d4090e6eb4196958d2c73958fefdfa864c0e7e69a5e8a589f198465b2e
4
- data.tar.gz: aa0739c73ce5359fe1f965e4c46674bf3a7d79a603d7bcc683f671cd5e039fd9
3
+ metadata.gz: a81e333f4fb405aaeadf79c3e41b65b8282ff8cbbcb5ffea959379e48e4209b0
4
+ data.tar.gz: bcb8cbf57ccc8b906efbfb350aac27b233163a207e0d7ea08afbb9803f35ce00
5
5
  SHA512:
6
- metadata.gz: fce61c75d5175ad6c7ae37263f3065efc796dc496dd290616bd6cf1bb69518149231e6da378f6ee5573a8f17d1a55e73179da30e46820a61b237038b62483ff3
7
- data.tar.gz: e7e2cadb887aaacb9fea39058bea689f087da8719ceba75931b768f92b170ca16bf2f93fe7731a18c4a5ebd00660ece4bfdf4f466f712bf98f7d74dc66d1e0b6
6
+ metadata.gz: d93bcd456a656aaf8dd375345715b9c39c272be02c9bac9345e84827c7aaa6809a8b0414103f38ac4492dd1690a6662b28c14a9ba50604942a81439aba2dd4b7
7
+ data.tar.gz: 612fb95319d7be645abbebb0a45442ae9549f3a51f757903bcc4f372d65831c1c72e5fbf52b821b8bd970c27543ff96e0a4901cdcc774dc4d0e1eb164c9f00af
data/Gemfile.lock CHANGED
@@ -12,7 +12,7 @@ GIT
12
12
  PATH
13
13
  remote: .
14
14
  specs:
15
- checkoff (0.109.0)
15
+ checkoff (0.110.0)
16
16
  activesupport
17
17
  asana (> 0.10.0)
18
18
  cache_method
@@ -37,6 +37,8 @@
37
37
  # def portfolios; end
38
38
  # # @return [Asana::ProxiedResourceClasses::User]
39
39
  # def users; end
40
+ # # @return [Asana::ProxiedResourceClasses::CustomField]
41
+ # def custom_fields; end
40
42
  # end
41
43
  # class Collection < Asana::Resources::Collection; end
42
44
  # module Resources
@@ -79,6 +81,15 @@
79
81
  # end
80
82
  # end
81
83
  # module ProxiedResourceClasses
84
+ # class CustomField
85
+ # # Get a workspace's custom fields
86
+ # #
87
+ # # @param workspace_gid [String] (required) Globally unique identifier for the workspace or organization.
88
+ # # @param options [Hash] the request I/O options
89
+ # #
90
+ # # @return [Enumerable<Asana::Resources::CustomField>]
91
+ # def get_custom_fields_for_workspace(workspace_gid: required("workspace_gid"), options: {}); end
92
+ # end
82
93
  # class Task
83
94
  # # Returns the complete task record for a single task.
84
95
  # #
@@ -30,11 +30,17 @@ module Checkoff
30
30
  # extend CacheMethod::ClassMethods
31
31
 
32
32
  MINUTE = 60
33
+ private_constant :MINUTE
33
34
  HOUR = MINUTE * 60
35
+ private_constant :HOUR
34
36
  DAY = 24 * HOUR
37
+ private_constant :DAY
35
38
  REALLY_LONG_CACHE_TIME = HOUR * 1
39
+ private_constant :REALLY_LONG_CACHE_TIME
36
40
  LONG_CACHE_TIME = MINUTE * 15
41
+ private_constant :LONG_CACHE_TIME
37
42
  SHORT_CACHE_TIME = MINUTE
43
+ private_constant :SHORT_CACHE_TIME
38
44
 
39
45
  # @param config [Hash]
40
46
  # @param workspaces [Checkoff::Workspaces]
@@ -13,6 +13,9 @@ require_relative 'clients'
13
13
  module Checkoff
14
14
  # Work with custom fields in Asana
15
15
  class CustomFields
16
+ # @!parse
17
+ # extend CacheMethod::ClassMethods
18
+
16
19
  MINUTE = 60
17
20
  HOUR = MINUTE * 60
18
21
  DAY = 24 * HOUR
@@ -20,22 +23,36 @@ module Checkoff
20
23
  LONG_CACHE_TIME = MINUTE * 15
21
24
  SHORT_CACHE_TIME = MINUTE
22
25
 
26
+ # @param config [Hash]
27
+ # @param workspaces [Checkoff::Workspaces]
28
+ # @param clients [Checkoff::Clients]
29
+ # @param client [Asana::Client]
23
30
  def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana),
24
- workspaces: Checkoff::Workspaces.new(config: config),
25
31
  clients: Checkoff::Clients.new(config: config),
26
- client: clients.client)
32
+ client: clients.client,
33
+ workspaces: Checkoff::Workspaces.new(config: config,
34
+ client: client))
27
35
  @workspaces = workspaces
28
36
  @client = client
29
37
  end
30
38
 
39
+ # @param workspace_name [String]
40
+ # @param custom_field_name [String]
41
+ #
42
+ # @return [Asana::Resources::CustomField]
31
43
  def custom_field_or_raise(workspace_name, custom_field_name)
32
- custom_field = custom_field(workspace_name, custom_field_name)
33
- raise "Could not find custom_field #{custom_field_name} under workspace #{workspace_name}." if custom_field.nil?
44
+ cf = custom_field(workspace_name, custom_field_name)
45
+ raise "Could not find custom_field #{custom_field_name} under workspace #{workspace_name}." if cf.nil?
34
46
 
35
- custom_field
47
+ cf
36
48
  end
37
49
  cache_method :custom_field_or_raise, LONG_CACHE_TIME
38
50
 
51
+ # @param workspace_name [String]
52
+ # @param custom_field_name [String]
53
+ #
54
+ # @sg-ignore
55
+ # @return [Asana::Resources::CustomField,nil]
39
56
  def custom_field(workspace_name, custom_field_name)
40
57
  workspace = workspaces.workspace_or_raise(workspace_name)
41
58
  custom_fields = client.custom_fields.get_custom_fields_for_workspace(workspace_gid: workspace.gid)
@@ -43,15 +60,133 @@ module Checkoff
43
60
  end
44
61
  cache_method :custom_field, LONG_CACHE_TIME
45
62
 
63
+ # @param resource [Asana::Resources::Project,Asana::Resources::Task]
64
+ # @param custom_field_gid [String]
65
+ #
66
+ # @return [Array<String>]
67
+ def resource_custom_field_values_gids_or_raise(resource, custom_field_gid)
68
+ custom_field = resource_custom_field_by_gid_or_raise(resource, custom_field_gid)
69
+
70
+ resource_custom_field_enum_values(custom_field).flat_map do |enum_value|
71
+ find_gids(custom_field, enum_value)
72
+ end
73
+ end
74
+
75
+ # @param resource [Asana::Resources::Project,Asana::Resources::Task]
76
+ # @param custom_field_name [String]
77
+ # @return [Array<String>]
78
+ def resource_custom_field_values_names_by_name(resource, custom_field_name)
79
+ custom_field = resource_custom_field_by_name(resource, custom_field_name)
80
+ return [] if custom_field.nil?
81
+
82
+ resource_custom_field_enum_values(custom_field).flat_map do |enum_value|
83
+ find_names(enum_value)
84
+ end
85
+ end
86
+
87
+ # @sg-ignore
88
+ # @param project [Asana::Resources::Task,Asana::Resources::Project]
89
+ # @param custom_field_name [String]
90
+ # @return [Hash, nil]
91
+ def resource_custom_field_by_name(resource, custom_field_name)
92
+ # @sg-ignore
93
+ # @type [Array<Hash>]
94
+ custom_fields = resource.custom_fields
95
+ if custom_fields.nil?
96
+ raise "custom fields not found on resource - did you add 'custom_fields' in your extra_fields argument?"
97
+ end
98
+
99
+ # @sg-ignore
100
+ # @type [Hash, nil]
101
+ custom_fields.find { |field| field.fetch('name') == custom_field_name }
102
+ end
103
+
104
+ # @param resource [Asana::Resources::Task,Asana::Resources::Project]
105
+ # @param custom_field_name [String]
106
+ # @return [Hash]
107
+ def resource_custom_field_by_name_or_raise(resource, custom_field_name)
108
+ custom_field = resource_custom_field_by_name(resource, custom_field_name)
109
+ if custom_field.nil?
110
+ raise "Could not find custom field with name #{custom_field_name} " \
111
+ "in gid #{resource.gid} with custom fields #{resource.custom_fields}"
112
+ end
113
+ custom_field
114
+ end
115
+
116
+ # @param resource [Asana::Resources::Project,Asana::Resources::Task]
117
+ # @param custom_field_gid [String]
118
+ # @return [Hash]
119
+ def resource_custom_field_by_gid_or_raise(resource, custom_field_gid)
120
+ # @type [Array<Hash>]
121
+ custom_fields = resource.custom_fields
122
+ if custom_fields.nil?
123
+ raise "Could not find custom_fields under project (was 'custom_fields' included in 'extra_fields'?)"
124
+ end
125
+
126
+ # @sg-ignore
127
+ # @type [Hash, nil]
128
+ matched_custom_field = custom_fields.find { |data| data.fetch('gid') == custom_field_gid }
129
+ if matched_custom_field.nil?
130
+ raise "Could not find custom field with gid #{custom_field_gid} " \
131
+ "in gid #{resource.gid} with custom fields #{custom_fields}"
132
+ end
133
+
134
+ matched_custom_field
135
+ end
136
+
46
137
  private
47
138
 
48
- attr_reader :workspaces, :client
139
+ # @sg-ignore
140
+ # @param custom_field [Hash]
141
+ # @return [Array<String>]
142
+ def resource_custom_field_enum_values(custom_field)
143
+ resource_subtype = custom_field.fetch('resource_subtype')
144
+ case resource_subtype
145
+ when 'enum'
146
+ [custom_field.fetch('enum_value')]
147
+ when 'multi_enum'
148
+ custom_field.fetch('multi_enum_values')
149
+ else
150
+ raise "Teach me how to handle resource_subtype #{resource_subtype}"
151
+ end
152
+ end
153
+
154
+ # @param custom_field [Hash]
155
+ # @param enum_value [Object, nil]
156
+ # @return [Array<String>]
157
+ def find_gids(custom_field, enum_value)
158
+ if enum_value.nil?
159
+ []
160
+ else
161
+ raise "Unexpected enabled value on custom field: #{custom_field}" if enum_value.fetch('enabled') == false
162
+
163
+ [enum_value.fetch('gid')]
164
+ end
165
+ end
166
+
167
+ # @param custom_field [Hash]
168
+ # @param enum_value [Object, nil]
169
+ # @return [Array<String>]
170
+ def find_names(enum_value)
171
+ [enum_value.fetch('name')]
172
+ end
173
+
174
+ # @return [Checkoff::Workspaces]
175
+ attr_reader :workspaces
176
+
177
+ # @return [Asana::Client]
178
+ attr_reader :client
49
179
 
50
180
  # bundle exec ./custom_fields.rb
51
181
  # :nocov:
52
182
  class << self
183
+ # @return [void]
53
184
  def run
185
+ # @sg-ignore
186
+ # @type [String]
54
187
  workspace_name = ARGV[0] || raise('Please pass workspace name as first argument')
188
+ # @sg-ignore
189
+ # @type [String]
55
190
  custom_field_name = ARGV[1] || raise('Please pass custom_field name as second argument')
56
191
  custom_fields = Checkoff::CustomFields.new
57
192
  custom_field = custom_fields.custom_field_or_raise(workspace_name, custom_field_name)
@@ -9,10 +9,13 @@ module Checkoff
9
9
  class ProjectSelectorEvaluator < SelectorEvaluator
10
10
  # @param project [Asana::Resources::Project]
11
11
  # @param projects [Checkoff::Projects]
12
+ # @param custom_fields [Checkoff::CustomFields]
12
13
  def initialize(project:,
13
- projects: Checkoff::Projects.new)
14
+ projects: Checkoff::Projects.new,
15
+ custom_fields: Checkoff::CustomFields.new)
14
16
  @item = project
15
17
  @projects = projects
18
+ @custom_fields = custom_fields
16
19
  super()
17
20
  end
18
21
 
@@ -35,12 +38,14 @@ module Checkoff
35
38
 
36
39
  # @return [Hash]
37
40
  def initializer_kwargs
38
- { projects: projects }
41
+ { projects: projects, custom_fields: custom_fields }
39
42
  end
40
43
 
41
44
  # @return [Asana::Resources::Project]
42
45
  attr_reader :item
43
46
  # @return [Checkoff::Projects]
44
47
  attr_reader :projects
48
+ # @return [Checkoff::CustomFields]
49
+ attr_reader :custom_fields
45
50
  end
46
51
  end
@@ -11,14 +11,18 @@ module Checkoff
11
11
  # @param client [Asana::Client]
12
12
  # @param projects [Checkoff::Projects]
13
13
  # @param sections [Checkoff::Sections]
14
+ # @param custom_fields [Checkoff::CustomFields]
14
15
  def initialize(section:,
15
16
  client:,
16
17
  projects: Checkoff::Projects.new(client: client),
17
- sections: Checkoff::Sections.new)
18
+ sections: Checkoff::Sections.new(client: client),
19
+ custom_fields: Checkoff::CustomFields.new(client: client),
20
+ **_kwargs)
18
21
  @item = section
19
22
  @client = client
20
23
  @projects = projects
21
24
  @sections = sections
25
+ @custom_fields = custom_fields
22
26
  super()
23
27
  end
24
28
 
@@ -41,7 +45,7 @@ module Checkoff
41
45
 
42
46
  # @return [Hash]
43
47
  def initializer_kwargs
44
- { sections: sections, projects: projects, client: client }
48
+ { sections: sections, projects: projects, client: client, custom_fields: custom_fields }
45
49
  end
46
50
 
47
51
  # @return [Asana::Resources::Project]
@@ -50,6 +54,8 @@ module Checkoff
50
54
  attr_reader :sections
51
55
  # @return [Checkoff::Projects]
52
56
  attr_reader :projects
57
+ # @return [Checkoff::CustomFields]
58
+ attr_reader :custom_fields
53
59
  # @return [Asana::Client]
54
60
  attr_reader :client
55
61
  end
@@ -8,122 +8,17 @@ module Checkoff
8
8
  # Base class to evaluate a project selector function given fully evaluated arguments
9
9
  class FunctionEvaluator < ::Checkoff::SelectorClasses::FunctionEvaluator
10
10
  # @param selector [Array<(Symbol, Array)>,String]
11
- def initialize(selector:, **_kwargs)
11
+ # @param custom_fields [Checkoff::CustomFields]
12
+ def initialize(selector:, custom_fields:, **_kwargs)
12
13
  @selector = selector
14
+ @custom_fields = custom_fields
13
15
  super()
14
16
  end
15
17
 
16
18
  private
17
19
 
18
- # @sg-ignore
19
- # @param project [Asana::Resources::Project]
20
- # @param custom_field_gid [String]
21
- # @return [Hash]
22
- def pull_custom_field_or_raise(project, custom_field_gid)
23
- # @type [Array<Hash>]
24
- custom_fields = project.custom_fields
25
- if custom_fields.nil?
26
- raise "Could not find custom_fields under project (was 'custom_fields' included in 'extra_fields'?)"
27
- end
28
-
29
- # @sg-ignore
30
- # @type [Hash, nil]
31
- matched_custom_field = custom_fields.find { |data| data.fetch('gid') == custom_field_gid }
32
- if matched_custom_field.nil?
33
- raise "Could not find custom field with gid #{custom_field_gid} " \
34
- "in project #{project.gid} with custom fields #{custom_fields}"
35
- end
36
-
37
- matched_custom_field
38
- end
39
-
40
20
  # @return [Array<(Symbol, Array)>]
41
21
  attr_reader :selector
42
-
43
- # @sg-ignore
44
- # @param custom_field [Hash]
45
- # @return [Array<String>]
46
- def pull_enum_values(custom_field)
47
- resource_subtype = custom_field.fetch('resource_subtype')
48
- case resource_subtype
49
- when 'enum'
50
- [custom_field.fetch('enum_value')]
51
- when 'multi_enum'
52
- custom_field.fetch('multi_enum_values')
53
- else
54
- raise "Teach me how to handle resource_subtype #{resource_subtype}"
55
- end
56
- end
57
-
58
- # @param custom_field [Hash]
59
- # @param enum_value [Object, nil]
60
- # @return [Array<String>]
61
- def find_gids(custom_field, enum_value)
62
- if enum_value.nil?
63
- []
64
- else
65
- raise "Unexpected enabled value on custom field: #{custom_field}" if enum_value.fetch('enabled') == false
66
-
67
- [enum_value.fetch('gid')]
68
- end
69
- end
70
-
71
- # @param custom_field [Hash]
72
- # @param enum_value [Object, nil]
73
- # @return [Array<String>]
74
- def find_names(enum_value)
75
- [enum_value.fetch('name')]
76
- end
77
-
78
- # @param project [Asana::Resources::Project,Asana::Resources::Task]
79
- # @param custom_field_gid [String]
80
- # @return [Array<String>]
81
- def pull_custom_field_values_gids_or_raise(project, custom_field_gid)
82
- custom_field = pull_custom_field_or_raise(project, custom_field_gid)
83
-
84
- pull_enum_values(custom_field).flat_map do |enum_value|
85
- find_gids(custom_field, enum_value)
86
- end
87
- end
88
-
89
- # @param resource [Asana::Resources::Project,Asana::Resources::Task]
90
- # @param custom_field_name [String]
91
- # @return [Array<String>]
92
- def pull_custom_field_values_names_by_name(resource, custom_field_name)
93
- custom_field = pull_custom_field_by_name(resource, custom_field_name)
94
- return [] if custom_field.nil?
95
-
96
- pull_enum_values(custom_field).flat_map do |enum_value|
97
- find_names(enum_value)
98
- end
99
- end
100
-
101
- # @sg-ignore
102
- # @param project [Asana::Resources::Project]
103
- # @param custom_field_name [String]
104
- # @return [Hash, nil]
105
- def pull_custom_field_by_name(project, custom_field_name)
106
- custom_fields = project.custom_fields
107
- if custom_fields.nil?
108
- raise "custom fields not found on project - did you add 'custom_fields' in your extra_fields argument?"
109
- end
110
-
111
- # @sg-ignore
112
- # @type [Hash, nil]
113
- custom_fields.find { |field| field.fetch('name') == custom_field_name }
114
- end
115
-
116
- # @param project [Asana::Resources::Project]
117
- # @param custom_field_name [String]
118
- # @return [Hash]
119
- def pull_custom_field_by_name_or_raise(project, custom_field_name)
120
- custom_field = pull_custom_field_by_name(project, custom_field_name)
121
- if custom_field.nil?
122
- raise "Could not find custom field with name #{custom_field_name} " \
123
- "in project #{project.gid} with custom fields #{project.custom_fields}"
124
- end
125
- custom_field
126
- end
127
22
  end
128
23
  end
129
24
  end
@@ -105,7 +105,7 @@ module Checkoff
105
105
  # @param custom_field_name [String]
106
106
  # @return [String, nil]
107
107
  def evaluate(resource, custom_field_name)
108
- custom_field = pull_custom_field_by_name(resource, custom_field_name)
108
+ custom_field = @custom_fields.resource_custom_field_by_name(resource, custom_field_name)
109
109
  return nil if custom_field.nil?
110
110
 
111
111
  custom_field['display_value']
@@ -127,7 +127,7 @@ module Checkoff
127
127
  # @param custom_field_gid [String]
128
128
  # @return [String, nil]
129
129
  def evaluate(resource, custom_field_gid)
130
- custom_field = pull_custom_field_or_raise(resource, custom_field_gid)
130
+ custom_field = @custom_fields.resource_custom_field_by_gid_or_raise(resource, custom_field_gid)
131
131
  custom_field['display_value']
132
132
  end
133
133
  end
@@ -149,7 +149,8 @@ module Checkoff
149
149
  # @param custom_field_values_gids [Array<String>]
150
150
  # @return [Boolean]
151
151
  def evaluate(resource, custom_field_gid, custom_field_values_gids)
152
- actual_custom_field_values_gids = pull_custom_field_values_gids_or_raise(resource, custom_field_gid)
152
+ actual_custom_field_values_gids = @custom_fields.resource_custom_field_values_gids_or_raise(resource,
153
+ custom_field_gid)
153
154
 
154
155
  actual_custom_field_values_gids.any? do |custom_field_value|
155
156
  custom_field_values_gids.include?(custom_field_value)
@@ -174,7 +175,9 @@ module Checkoff
174
175
  # @param custom_field_value_names [Array<String>]
175
176
  # @return [Boolean]
176
177
  def evaluate(resource, custom_field_name, custom_field_value_names)
177
- actual_custom_field_values_names = pull_custom_field_values_names_by_name(resource, custom_field_name)
178
+ actual_custom_field_values_names =
179
+ @custom_fields.resource_custom_field_values_names_by_name(resource,
180
+ custom_field_name)
178
181
 
179
182
  actual_custom_field_values_names.any? do |custom_field_value|
180
183
  custom_field_value_names.include?(custom_field_value)
@@ -199,7 +202,9 @@ module Checkoff
199
202
  # @param custom_field_values_gids [Array<String>]
200
203
  # @return [Boolean]
201
204
  def evaluate(resource, custom_field_gid, custom_field_values_gids)
202
- actual_custom_field_values_gids = pull_custom_field_values_gids_or_raise(resource, custom_field_gid)
205
+ actual_custom_field_values_gids =
206
+ @custom_fields.resource_custom_field_values_gids_or_raise(resource,
207
+ custom_field_gid)
203
208
 
204
209
  custom_field_values_gids.all? do |custom_field_value|
205
210
  actual_custom_field_values_gids.include?(custom_field_value)
@@ -10,7 +10,8 @@ module Checkoff
10
10
  # @param selector [Array<(Symbol, Array)>,String]
11
11
  # @param projects [Checkoff::Projects]
12
12
  def initialize(selector:,
13
- projects:)
13
+ projects:,
14
+ **_kwargs)
14
15
  @selector = selector
15
16
  @projects = projects
16
17
  super()
@@ -18,95 +19,8 @@ module Checkoff
18
19
 
19
20
  private
20
21
 
21
- # @sg-ignore
22
- # @param project [Asana::Resources::Project]
23
- # @param custom_field_gid [String]
24
- # @return [Hash]
25
- def pull_custom_field_or_raise(project, custom_field_gid)
26
- # @type [Array<Hash>]
27
- custom_fields = project.custom_fields
28
- if custom_fields.nil?
29
- raise "Could not find custom_fields under project (was 'custom_fields' included in 'extra_fields'?)"
30
- end
31
-
32
- # @sg-ignore
33
- # @type [Hash, nil]
34
- matched_custom_field = custom_fields.find { |data| data.fetch('gid') == custom_field_gid }
35
- if matched_custom_field.nil?
36
- raise "Could not find custom field with gid #{custom_field_gid} " \
37
- "in project #{project.gid} with custom fields #{custom_fields}"
38
- end
39
-
40
- matched_custom_field
41
- end
42
-
43
22
  # @return [Array<(Symbol, Array)>]
44
23
  attr_reader :selector
45
-
46
- # @sg-ignore
47
- # @param custom_field [Hash]
48
- # @return [Array<String>]
49
- def pull_enum_values(custom_field)
50
- resource_subtype = custom_field.fetch('resource_subtype')
51
- case resource_subtype
52
- when 'enum'
53
- [custom_field.fetch('enum_value')]
54
- when 'multi_enum'
55
- custom_field.fetch('multi_enum_values')
56
- else
57
- raise "Teach me how to handle resource_subtype #{resource_subtype}"
58
- end
59
- end
60
-
61
- # @param custom_field [Hash]
62
- # @param enum_value [Object, nil]
63
- # @return [Array<String>]
64
- def find_gids(custom_field, enum_value)
65
- if enum_value.nil?
66
- []
67
- else
68
- raise "Unexpected enabled value on custom field: #{custom_field}" if enum_value.fetch('enabled') == false
69
-
70
- [enum_value.fetch('gid')]
71
- end
72
- end
73
-
74
- # @param project [Asana::Resources::Project]
75
- # @param custom_field_gid [String]
76
- # @return [Array<String>]
77
- def pull_custom_field_values_gids(project, custom_field_gid)
78
- custom_field = pull_custom_field_or_raise(project, custom_field_gid)
79
- pull_enum_values(custom_field).flat_map do |enum_value|
80
- find_gids(custom_field, enum_value)
81
- end
82
- end
83
-
84
- # @sg-ignore
85
- # @param project [Asana::Resources::Project]
86
- # @param custom_field_name [String]
87
- # @return [Hash, nil]
88
- def pull_custom_field_by_name(project, custom_field_name)
89
- custom_fields = project.custom_fields
90
- if custom_fields.nil?
91
- raise "custom fields not found on project - did you add 'custom_fields' in your extra_fields argument?"
92
- end
93
-
94
- # @sg-ignore
95
- # @type [Hash, nil]
96
- custom_fields.find { |field| field.fetch('name') == custom_field_name }
97
- end
98
-
99
- # @param project [Asana::Resources::Project]
100
- # @param custom_field_name [String]
101
- # @return [Hash]
102
- def pull_custom_field_by_name_or_raise(project, custom_field_name)
103
- custom_field = pull_custom_field_by_name(project, custom_field_name)
104
- if custom_field.nil?
105
- raise "Could not find custom field with name #{custom_field_name} " \
106
- "in project #{project.gid} with custom fields #{project.custom_fields}"
107
- end
108
- custom_field
109
- end
110
24
  end
111
25
  end
112
26
  end
@@ -7,7 +7,7 @@ module Checkoff
7
7
  # Section selector classes
8
8
  module Section
9
9
  # :ends_with_milestone function
10
- class DueDateFunctionEvaluator < FunctionEvaluator
10
+ class EndsWithMilestoneFunctionEvaluator < FunctionEvaluator
11
11
  FUNCTION_NAME = :ends_with_milestone
12
12
 
13
13
  def matches?
@@ -10,106 +10,23 @@ module Checkoff
10
10
  # @param selector [Array<(Symbol, Array)>,String]
11
11
  # @param tasks [Checkoff::Tasks]
12
12
  # @param timelines [Checkoff::Timelines]
13
+ # @param custom_fields [Checkoff::CustomFields]
13
14
  def initialize(selector:,
14
15
  tasks:,
15
- timelines:)
16
+ timelines:,
17
+ custom_fields:,
18
+ **_kwargs)
16
19
  @selector = selector
17
20
  @tasks = tasks
18
21
  @timelines = timelines
22
+ @custom_fields = custom_fields
19
23
  super()
20
24
  end
21
25
 
22
26
  private
23
27
 
24
- # @sg-ignore
25
- # @param task [Asana::Resources::Task]
26
- # @param custom_field_gid [String]
27
- # @return [Hash]
28
- def pull_custom_field_or_raise(task, custom_field_gid)
29
- # @type [Array<Hash>]
30
- custom_fields = task.custom_fields
31
- if custom_fields.nil?
32
- raise "Could not find custom_fields under task (was 'custom_fields' included in 'extra_fields'?)"
33
- end
34
-
35
- # @sg-ignore
36
- # @type [Hash, nil]
37
- matched_custom_field = custom_fields.find { |data| data.fetch('gid') == custom_field_gid }
38
- if matched_custom_field.nil?
39
- raise "Could not find custom field with gid #{custom_field_gid} " \
40
- "in task #{task.gid} with custom fields #{custom_fields}"
41
- end
42
-
43
- matched_custom_field
44
- end
45
-
46
28
  # @return [Array<(Symbol, Array)>]
47
29
  attr_reader :selector
48
-
49
- # @sg-ignore
50
- # @param custom_field [Hash]
51
- # @return [Array<String>]
52
- def pull_enum_values(custom_field)
53
- resource_subtype = custom_field.fetch('resource_subtype')
54
- case resource_subtype
55
- when 'enum'
56
- [custom_field.fetch('enum_value')]
57
- when 'multi_enum'
58
- custom_field.fetch('multi_enum_values')
59
- else
60
- raise "Teach me how to handle resource_subtype #{resource_subtype}"
61
- end
62
- end
63
-
64
- # @param custom_field [Hash]
65
- # @param enum_value [Object, nil]
66
- # @return [Array<String>]
67
- def find_gids(custom_field, enum_value)
68
- if enum_value.nil?
69
- []
70
- else
71
- raise "Unexpected enabled value on custom field: #{custom_field}" if enum_value.fetch('enabled') == false
72
-
73
- [enum_value.fetch('gid')]
74
- end
75
- end
76
-
77
- # @param task [Asana::Resources::Task]
78
- # @param custom_field_gid [String]
79
- # @return [Array<String>]
80
- def pull_custom_field_values_gids(task, custom_field_gid)
81
- custom_field = pull_custom_field_or_raise(task, custom_field_gid)
82
- pull_enum_values(custom_field).flat_map do |enum_value|
83
- find_gids(custom_field, enum_value)
84
- end
85
- end
86
-
87
- # @sg-ignore
88
- # @param task [Asana::Resources::Task]
89
- # @param custom_field_name [String]
90
- # @return [Hash, nil]
91
- def pull_custom_field_by_name(task, custom_field_name)
92
- custom_fields = task.custom_fields
93
- if custom_fields.nil?
94
- raise "custom fields not found on task - did you add 'custom_fields' in your extra_fields argument?"
95
- end
96
-
97
- # @sg-ignore
98
- # @type [Hash, nil]
99
- custom_fields.find { |field| field.fetch('name') == custom_field_name }
100
- end
101
-
102
- # @param task [Asana::Resources::Task]
103
- # @param custom_field_name [String]
104
- # @return [Hash]
105
- def pull_custom_field_by_name_or_raise(task, custom_field_name)
106
- custom_field = pull_custom_field_by_name(task, custom_field_name)
107
- if custom_field.nil?
108
- raise "Could not find custom field with name #{custom_field_name} " \
109
- "in task #{task.gid} with custom fields #{task.custom_fields}"
110
- end
111
- custom_field
112
- end
113
30
  end
114
31
  end
115
32
  end
@@ -190,7 +190,7 @@ module Checkoff
190
190
  # @param num_days [Integer]
191
191
  # @return [Boolean]
192
192
  def evaluate(task, custom_field_name, num_days)
193
- custom_field = pull_custom_field_by_name_or_raise(task, custom_field_name)
193
+ custom_field = @custom_fields.resource_custom_field_by_name_or_raise(task, custom_field_name)
194
194
 
195
195
  # @sg-ignore
196
196
  # @type [String, nil]
@@ -220,7 +220,7 @@ module Checkoff
220
220
  # @param num_days [Integer]
221
221
  # @return [Boolean]
222
222
  def evaluate(task, custom_field_name, num_days)
223
- custom_field = pull_custom_field_by_name_or_raise(task, custom_field_name)
223
+ custom_field = @custom_fields.resource_custom_field_by_name_or_raise(task, custom_field_name)
224
224
 
225
225
  # @sg-ignore
226
226
  # @type [String, nil]
@@ -289,7 +289,7 @@ module Checkoff
289
289
  # @param task [Asana::Resources::Task]
290
290
  # @return [Boolean]
291
291
  def evaluate(task)
292
- custom_field = pull_custom_field_by_name(task, 'Estimated time')
292
+ custom_field = @custom_fields.resource_custom_field_by_name(task, 'Estimated time')
293
293
 
294
294
  return false if custom_field.nil?
295
295
 
@@ -10,12 +10,15 @@ module Checkoff
10
10
  # @param task [Asana::Resources::Task]
11
11
  # @param tasks [Checkoff::Tasks]
12
12
  # @param timelines [Checkoff::Timelines]
13
+ # @param custom_fields [Checkoff::CustomFields]
13
14
  def initialize(task:,
14
15
  tasks: Checkoff::Tasks.new,
15
- timelines: Checkoff::Timelines.new)
16
+ timelines: Checkoff::Timelines.new,
17
+ custom_fields: Checkoff::CustomFields.new)
16
18
  @item = task
17
19
  @tasks = tasks
18
20
  @timelines = timelines
21
+ @custom_fields = custom_fields
19
22
  super()
20
23
  end
21
24
 
@@ -38,7 +41,7 @@ module Checkoff
38
41
 
39
42
  # @return [Hash]
40
43
  def initializer_kwargs
41
- { tasks: tasks, timelines: timelines }
44
+ { tasks: tasks, timelines: timelines, custom_fields: custom_fields }
42
45
  end
43
46
 
44
47
  # @return [Asana::Resources::Task]
@@ -47,5 +50,7 @@ module Checkoff
47
50
  attr_reader :tasks
48
51
  # @return [Checkoff::Timelines]
49
52
  attr_reader :timelines
53
+ # @return [Checkoff::CustomFields]
54
+ attr_reader :custom_fields
50
55
  end
51
56
  end
@@ -22,15 +22,18 @@ module Checkoff
22
22
  # @param config [Hash<Symbol, Object>]
23
23
  # @param workspaces [Checkoff::Workspaces]
24
24
  # @param projects [Checkoff::Projects]
25
+ # @param custom_fields [Checkoff::CustomFields]
25
26
  # @param clients [Checkoff::Clients]
26
27
  # @param client [Asana::Client]
27
28
  def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana),
28
29
  workspaces: Checkoff::Workspaces.new(config: config),
29
30
  projects: Checkoff::Projects.new(config: config),
31
+ custom_fields: Checkoff::CustomFields.new(config: config),
30
32
  clients: Checkoff::Clients.new(config: config),
31
33
  client: clients.client)
32
34
  @workspaces = workspaces
33
35
  @projects = projects
36
+ @custom_fields = custom_fields
34
37
  @client = client
35
38
  end
36
39
 
@@ -39,7 +42,7 @@ module Checkoff
39
42
  # project details. Examples: [:tag, 'foo'] [:not, [:tag, 'foo']] [:tag, 'foo']
40
43
  # @return [Boolean]
41
44
  def filter_via_project_selector(project, project_selector)
42
- evaluator = ProjectSelectorEvaluator.new(project: project, projects: projects)
45
+ evaluator = ProjectSelectorEvaluator.new(project: project, projects: projects, custom_fields: custom_fields)
43
46
  evaluator.evaluate(project_selector)
44
47
  end
45
48
 
@@ -51,6 +54,9 @@ module Checkoff
51
54
  # @return [Checkoff::Projects]
52
55
  attr_reader :projects
53
56
 
57
+ # @return [Checkoff::CustomFields]
58
+ attr_reader :custom_fields
59
+
54
60
  # @return [Asana::Client]
55
61
  attr_reader :client
56
62
 
@@ -22,15 +22,18 @@ module Checkoff
22
22
  # @param config [Hash<Symbol, Object>]
23
23
  # @param workspaces [Checkoff::Workspaces]
24
24
  # @param sections [Checkoff::Sections]
25
+ # @param custom_fields [Checkoff::CustomFields]
25
26
  # @param clients [Checkoff::Clients]
26
27
  # @param client [Asana::Client]
27
28
  def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana),
28
29
  workspaces: Checkoff::Workspaces.new(config: config),
29
30
  sections: Checkoff::Sections.new(config: config),
31
+ custom_fields: Checkoff::CustomFields.new(config: config),
30
32
  clients: Checkoff::Clients.new(config: config),
31
33
  client: clients.client)
32
34
  @workspaces = workspaces
33
35
  @sections = sections
36
+ @custom_fields = custom_fields
34
37
  @client = client
35
38
  end
36
39
 
@@ -40,7 +43,8 @@ module Checkoff
40
43
  # @return [Boolean]
41
44
  def filter_via_section_selector(section, section_selector)
42
45
  # @sg-ignore
43
- evaluator = SectionSelectorEvaluator.new(section: section, sections: sections, client: client)
46
+ evaluator = SectionSelectorEvaluator.new(section: section, sections: sections, custom_fields: custom_fields,
47
+ client: client)
44
48
  evaluator.evaluate(section_selector)
45
49
  end
46
50
 
@@ -52,6 +56,9 @@ module Checkoff
52
56
  # @return [Checkoff::Sections]
53
57
  attr_reader :sections
54
58
 
59
+ # @return [Checkoff::CustomFields]
60
+ attr_reader :custom_fields
61
+
55
62
  # @return [Asana::Client]
56
63
  attr_reader :client
57
64
 
@@ -29,10 +29,13 @@ module Checkoff
29
29
  tasks: Checkoff::Tasks.new(config: config,
30
30
  client: client),
31
31
  timelines: Checkoff::Timelines.new(config: config,
32
- client: client))
32
+ client: client),
33
+ custom_fields: Checkoff::CustomFields.new(config: config,
34
+ client: client))
33
35
  @config = config
34
36
  @tasks = tasks
35
37
  @timelines = timelines
38
+ @custom_fields = custom_fields
36
39
  end
37
40
 
38
41
  # @param [Asana::Resources::Task] task
@@ -40,7 +43,8 @@ module Checkoff
40
43
  # task details. Examples: [:tag, 'foo'] [:not, [:tag, 'foo']] [:tag, 'foo']
41
44
  # @return [Boolean]
42
45
  def filter_via_task_selector(task, task_selector)
43
- evaluator = TaskSelectorEvaluator.new(task: task, tasks: tasks, timelines: timelines)
46
+ evaluator = TaskSelectorEvaluator.new(task: task, tasks: tasks, timelines: timelines,
47
+ custom_fields: custom_fields)
44
48
  evaluator.evaluate(task_selector)
45
49
  end
46
50
 
@@ -52,6 +56,9 @@ module Checkoff
52
56
  # @return [Checkoff::Timelines]
53
57
  attr_reader :timelines
54
58
 
59
+ # @return [Checkoff::CustomFields]
60
+ attr_reader :custom_fields
61
+
55
62
  # bundle exec ./task_selectors.rb
56
63
  # :nocov:
57
64
  class << self
@@ -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.109.0'
6
+ VERSION = '0.110.0'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checkoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.109.0
4
+ version: 0.110.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vince Broz