checkoff 0.22.0 → 0.24.0

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: '084d67648e9668ace7b8d103e4e1f9ec1d8d66bb0048cc1f8c7d652dd115397c'
4
- data.tar.gz: e1cf9b3f5639841462290ac1a5228fa5ca3dba3d4e70c62d84644184e63e6b89
3
+ metadata.gz: 26474f8f2f94c75d46d16eadd8c773a22d139d56e0d4bcaaae4c698519e8fa89
4
+ data.tar.gz: fc1b3a92a5736360fec289c1f2c156bc6570ad465fe8ecfdaa63a1b5a10cef5f
5
5
  SHA512:
6
- metadata.gz: f49cd3bded68cdcc502b26ac03fe6b7e073aaa93294c4104b36c7bfb014fbbc9e3a792fb85d712e39251ec13ce1e7430e067c06a3075120bb37bcf23de457672
7
- data.tar.gz: a4886b2dabc6332688434e0bce0009c1bf1db10b97588f857dc729320b5f840e4f8368afaf03ea78bdbf2e1025c1f4fa9d23839d19d0df8fa2650839226915f0
6
+ metadata.gz: 80a903a43039264b205cb4ae61f4637360d8a9b4db4cf47062fd4d8e0ed127f420e6da5baebb30c2cbde792261c2265133157f45a19f7cfea8f0577b862327ac
7
+ data.tar.gz: f6a30feeda861f28f96bb8a7a6b38d68bd3a4042bf21b7521c4382c1b2107aeee8a04c405d5f79fe7fec0acfe27bce778f48ff93c00d27bc552b3f0e531a0359
data/Gemfile.lock CHANGED
@@ -12,7 +12,7 @@ GIT
12
12
  PATH
13
13
  remote: .
14
14
  specs:
15
- checkoff (0.22.0)
15
+ checkoff (0.24.0)
16
16
  activesupport
17
17
  asana (> 0.10.0)
18
18
  cache_method
@@ -48,6 +48,8 @@ module Checkoff
48
48
  'no_value' => CustomFieldVariant::NoValue,
49
49
  'is_not' => CustomFieldVariant::IsNot,
50
50
  'less_than' => CustomFieldVariant::LessThan,
51
+ 'greater_than' => CustomFieldVariant::GreaterThan,
52
+ 'doesnt_contain_any' => CustomFieldVariant::DoesntContainAny,
51
53
  }.freeze
52
54
 
53
55
  def convert_single_custom_field_params(gid, single_custom_field_params)
@@ -3,6 +3,7 @@
3
3
  module Checkoff
4
4
  module Internal
5
5
  module SearchUrl
6
+ # https://developers.asana.com/docs/search-tasks-in-a-workspace
6
7
  module CustomFieldVariant
7
8
  # base class for handling different custom_field_#{gid}.variant params
8
9
  class CustomFieldVariant
@@ -14,56 +15,67 @@ module Checkoff
14
15
  private
15
16
 
16
17
  attr_reader :gid, :remaining_params
17
- end
18
18
 
19
- # custom_field_#{gid}.variant = 'less_than'
20
- class LessThan < CustomFieldVariant
21
- def convert
22
- max_param = "custom_field_#{gid}.max"
19
+ def fetch_solo_param(param_name)
23
20
  case remaining_params.keys
24
- when [max_param]
25
- convert_single_custom_field_less_than_params_max_param(max_param)
21
+ when [param_name]
22
+ param_values = remaining_params.fetch(param_name)
23
+ unless param_values.length == 1
24
+ raise "Teach me how to handle these remaining keys for #{param_name}: #{remaining_params}"
25
+ end
26
+
27
+ param_values[0]
26
28
  else
27
29
  raise "Teach me how to handle #{remaining_params}"
28
30
  end
29
31
  end
32
+ end
30
33
 
31
- private
32
-
33
- def convert_single_custom_field_less_than_params_max_param(max_param)
34
- max_values = remaining_params.fetch(max_param)
35
- unless max_values.length == 1
36
- raise "Teach me how to handle these remaining keys for #{max_param}: #{remaining_params}"
37
- end
38
-
39
- max_value = max_values[0]
34
+ # custom_field_#{gid}.variant = 'less_than'
35
+ class LessThan < CustomFieldVariant
36
+ def convert
37
+ max_value = fetch_solo_param("custom_field_#{gid}.max")
40
38
  empty_task_selector = []
41
39
  [{ "custom_fields.#{gid}.less_than" => max_value }, empty_task_selector]
42
40
  end
43
41
  end
44
42
 
43
+ # custom_field_#{gid}.variant = 'greater_than'
44
+ class GreaterThan < CustomFieldVariant
45
+ def convert
46
+ max_value = fetch_solo_param("custom_field_#{gid}.min")
47
+ empty_task_selector = []
48
+ [{ "custom_fields.#{gid}.greater_than" => max_value }, empty_task_selector]
49
+ end
50
+ end
51
+
52
+ # This is used in the UI for select fields
53
+ #
45
54
  # custom_field_#{gid}.variant = 'is_not'
46
55
  class IsNot < CustomFieldVariant
47
56
  def convert
48
- case remaining_params.keys
49
- when ["custom_field_#{gid}.selected_options"]
50
- convert_single_custom_field_is_not_params_selected_options
51
- else
52
- raise "Teach me how to handle #{remaining_params}"
53
- end
54
- end
57
+ selected_options = fetch_solo_param("custom_field_#{gid}.selected_options").split('~')
55
58
 
56
- private
59
+ [{ "custom_fields.#{gid}.is_set" => 'true' },
60
+ ['not',
61
+ ['custom_field_gid_value_contains_any_gid',
62
+ gid,
63
+ selected_options]]]
64
+ end
65
+ end
57
66
 
58
- def convert_single_custom_field_is_not_params_selected_options
59
- selected_options = remaining_params.fetch("custom_field_#{gid}.selected_options")
60
- raise "Teach me how to handle #{remaining_params}" unless selected_options.length == 1
67
+ # This is used in the UI for multi-select fields
68
+ #
69
+ # custom_field_#{gid}.variant = 'doesnt_contain_any'
70
+ class DoesntContainAny < CustomFieldVariant
71
+ def convert
72
+ selected_options = fetch_solo_param("custom_field_#{gid}.selected_options").split('~')
61
73
 
62
74
  [{ "custom_fields.#{gid}.is_set" => 'true' },
63
75
  ['not',
64
76
  ['custom_field_gid_value_contains_any_gid',
65
77
  gid,
66
- selected_options.fetch(0).split('~')]]]
78
+ selected_options]]]
67
79
  end
68
80
  end
69
81
 
@@ -105,24 +105,40 @@ module Checkoff
105
105
  end
106
106
 
107
107
  matched_custom_field = custom_fields.find { |data| data.fetch('gid') == custom_field_gid }
108
- raise "Could not find custom field with gid #{custom_field_gid}" if matched_custom_field.nil?
108
+ if matched_custom_field.nil?
109
+ raise "Could not find custom field with gid #{custom_field_gid} in #{task.gid} with #{custom_fields}"
110
+ end
109
111
 
110
112
  matched_custom_field
111
113
  end
112
114
 
113
- def pull_custom_field_values_gids(task, custom_field_gid)
114
- matched_custom_field = pull_custom_field_or_raise(task, custom_field_gid)
115
+ def pull_enum_values(custom_field)
116
+ resource_subtype = custom_field.fetch('resource_subtype')
117
+ case resource_subtype
118
+ when 'enum'
119
+ [custom_field.fetch('enum_value')]
120
+ when 'multi_enum'
121
+ custom_field.fetch('multi_enum_values')
122
+ else
123
+ raise "Teach me how to handle resource_subtype #{resource_subtype}"
124
+ end
125
+ end
115
126
 
116
- enum_value = matched_custom_field.fetch('enum_value')
117
- actual_custom_field_values_gids = []
118
- unless enum_value.nil?
119
- if enum_value.fetch('enabled') == false
120
- raise "Unexpected enabled value on custom field: #{matched_custom_field}"
121
- end
127
+ def find_gids(custom_field, enum_value)
128
+ if enum_value.nil?
129
+ []
130
+ else
131
+ raise "Unexpected enabled value on custom field: #{custom_field}" if enum_value.fetch('enabled') == false
122
132
 
123
- actual_custom_field_values_gids = [enum_value.fetch('gid')]
133
+ [enum_value.fetch('gid')]
134
+ end
135
+ end
136
+
137
+ def pull_custom_field_values_gids(task, custom_field_gid)
138
+ custom_field = pull_custom_field_or_raise(task, custom_field_gid)
139
+ pull_enum_values(custom_field).flat_map do |enum_value|
140
+ find_gids(custom_field, enum_value)
124
141
  end
125
- actual_custom_field_values_gids
126
142
  end
127
143
  end
128
144
 
@@ -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.22.0'
6
+ VERSION = '0.24.0'
7
7
  end
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.22.0
4
+ version: 0.24.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-01-09 00:00:00.000000000 Z
11
+ date: 2023-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport