checkoff 0.106.0 → 0.108.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: d1113a5ffbcd7bbe80ffd702559e8be32741468c788b26b976d8bb33ce50c06b
4
- data.tar.gz: 91fb42cdc5620a932033d43eab190c46191c11794004b358a92bc6e40f97818d
3
+ metadata.gz: a6f58b9f4020d786886f43c7c3422b55b99143796be35fcccf7d46cc6d3369d8
4
+ data.tar.gz: 39b470be2c13d3e32d545f9914d935ee1fb8a8f2705e5cdb799a2ae2bab8bf71
5
5
  SHA512:
6
- metadata.gz: 18746c467511ea53db664dd7194ce8b9aeb432ae4fac74911db3d775a921fb7abb9ee8e1ce16e83c2ad1e31b4baf9cf79efb180b827579f040007729f7a6fc20
7
- data.tar.gz: 81645f19b209186e1e27d8d07bb5e9792eb9127462fa12af8518f71ee5baf2a8b721a2fe2060fb24ab4dc5291b817b27c8370e6b452e9c49a52b7cae3226567a
6
+ metadata.gz: df03add2cd762e7e4ce70ec769d316d96b718f59eb418c340557822894f202d28b92796ae0d02e42b5e9e8d1f1ca607c294a4ce64ac92e71e1a6a556d4eeba72
7
+ data.tar.gz: 89ad98040c6ea65313d51206394f5af2ddcd2671a0b9ea403ecbf3466df564dbe7e09f64932838d7f8d06302d9abf9c29dd8f8dbaad28cf2342795269e5ec2f5
data/Gemfile.lock CHANGED
@@ -12,7 +12,7 @@ GIT
12
12
  PATH
13
13
  remote: .
14
14
  specs:
15
- checkoff (0.106.0)
15
+ checkoff (0.108.0)
16
16
  activesupport
17
17
  asana (> 0.10.0)
18
18
  cache_method
@@ -94,7 +94,7 @@ module Checkoff
94
94
  def evaluate(task, period = :now_or_before, ignore_dependencies = false)
95
95
  @tasks.task_ready?(task, period: period, ignore_dependencies: ignore_dependencies)
96
96
  end
97
- # rubocop:ensable Style/OptionalBooleanParameter
97
+ # rubocop:enable Style/OptionalBooleanParameter
98
98
  end
99
99
 
100
100
  # :unassigned function
@@ -171,16 +171,7 @@ module Checkoff
171
171
  #
172
172
  # @return [Boolean]
173
173
  def evaluate(task, field_name, num_days)
174
- task_timing = Checkoff::Internal::TaskTiming.new
175
-
176
- date = task_timing.date_or_time_field_by_name(task, field_name)&.to_date
177
-
178
- return false if date.nil?
179
-
180
- # @sg-ignore
181
- n_days_ago = Date.today - num_days
182
- # @sg-ignore
183
- date < n_days_ago
174
+ @tasks.in_period?(task, field_name, [:less_than_n_days_ago, num_days])
184
175
  end
185
176
  end
186
177
 
@@ -202,15 +193,7 @@ module Checkoff
202
193
  #
203
194
  # @return [Boolean]
204
195
  def evaluate(task, field_name, num_days)
205
- task_timing = Checkoff::Internal::TaskTiming.new
206
- date = task_timing.date_or_time_field_by_name(task, field_name)&.to_date
207
-
208
- return false if date.nil?
209
-
210
- # @sg-ignore
211
- n_days_from_today = Date.today + num_days
212
- # @sg-ignore
213
- date >= n_days_from_today
196
+ @tasks.in_period?(task, field_name, [:greater_than_or_equal_to_n_days_from_today, num_days])
214
197
  end
215
198
  end
216
199
 
@@ -28,9 +28,9 @@ module Checkoff
28
28
  # @param clients [Checkoff::Clients]
29
29
  # @param client [Asana::Client]
30
30
  def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana),
31
- workspaces: Checkoff::Workspaces.new(config: config),
32
31
  clients: Checkoff::Clients.new(config: config),
33
- client: clients.client)
32
+ client: clients.client,
33
+ workspaces: Checkoff::Workspaces.new(config: config, client: client))
34
34
  @workspaces = workspaces
35
35
  @client = client
36
36
  end
@@ -67,9 +67,15 @@ module Checkoff
67
67
  # @param period [Symbol<:now_or_before,:this_week>]
68
68
  # @param ignore_dependencies [Boolean]
69
69
  def task_ready?(task, period: :now_or_before, ignore_dependencies: false)
70
- field_name = :ready
71
70
  return false if !ignore_dependencies && incomplete_dependencies?(task)
72
71
 
72
+ in_period?(task, :ready, period)
73
+ end
74
+
75
+ # @param task [Asana::Resources::Task]
76
+ # @param field_name [Symbol]
77
+ # @param period [Symbol<:now_or_before,:this_week>,Array] See Checkoff::Timing#in_period?_
78
+ def in_period?(task, field_name, period)
73
79
  # @type [Date,Time,nil]
74
80
  task_date_or_time = task_timing.date_or_time_field_by_name(task, field_name)
75
81
 
@@ -31,14 +31,9 @@ module Checkoff
31
31
  end
32
32
 
33
33
  # @param date_or_time [Date,Time,nil]
34
- def now_or_before?(date_or_time)
35
- return true if date_or_time.nil?
36
-
37
- date_or_time.to_time < @now_getter.now
38
- end
39
-
40
- # @param date_or_time [Date,Time,nil]
41
- # @param period [Symbol<:indefinite>]
34
+ # @param period [Symbol,Array<(Symbol,Integer)>]
35
+ #
36
+ # Valid values: :this_week, :now_or_before, :indefinite, [:less_than_n_days_ago, Integer]
42
37
  def in_period?(date_or_time, period)
43
38
  return this_week?(date_or_time) if period == :this_week
44
39
 
@@ -46,11 +41,46 @@ module Checkoff
46
41
 
47
42
  return now_or_before?(date_or_time) if period == :now_or_before
48
43
 
44
+ if period.is_a?(Array)
45
+ # @sg-ignore
46
+ # @type [Symbol]
47
+ period_name = period.first
48
+ args = period[1..]
49
+
50
+ return compound_in_period?(date_or_time, period_name, *args)
51
+ end
52
+
49
53
  raise "Teach me how to handle period #{period.inspect}"
50
54
  end
51
55
 
52
56
  private
53
57
 
58
+ # @param date_or_time [Date,Time,nil]
59
+ # @param num_days [Integer]
60
+ def greater_than_or_equal_to_n_days_from_today?(date_or_time, num_days)
61
+ return false if date_or_time.nil?
62
+
63
+ date = date_or_time.to_date
64
+
65
+ # @sg-ignore
66
+ n_days_from_today = @today_getter.today + num_days
67
+ # @sg-ignore
68
+ date >= n_days_from_today
69
+ end
70
+
71
+ # @param date_or_time [Date,Time,nil]
72
+ # @param num_days [Integer]
73
+ def less_than_n_days_ago?(date_or_time, num_days)
74
+ return false if date_or_time.nil?
75
+
76
+ date = date_or_time.to_date
77
+
78
+ # @sg-ignore
79
+ n_days_ago = @today_getter.today - num_days
80
+ # @sg-ignore
81
+ date < n_days_ago
82
+ end
83
+
54
84
  # @param date_or_time [Date,Time,nil]
55
85
  def this_week?(date_or_time)
56
86
  return true if date_or_time.nil?
@@ -68,6 +98,27 @@ module Checkoff
68
98
  date >= beginning_of_week && date <= end_of_week
69
99
  end
70
100
 
101
+ # @param date_or_time [Date,Time,nil]
102
+ def now_or_before?(date_or_time)
103
+ return true if date_or_time.nil?
104
+
105
+ date_or_time.to_time < @now_getter.now
106
+ end
107
+
108
+ # @param date_or_time [Date,Time,nil]
109
+ # @param period_name [Symbol]
110
+ # @param args [Object]
111
+ def compound_in_period?(date_or_time, period_name, *args)
112
+ # @sg-ignore
113
+ return less_than_n_days_ago?(date_or_time, *args) if period_name == :less_than_n_days_ago
114
+
115
+ if period_name == :greater_than_or_equal_to_n_days_from_today
116
+ return greater_than_or_equal_to_n_days_from_today?(date_or_time,
117
+ *args)
118
+ end
119
+ raise "Teach me how to handle period [#{period_name.inspect}, #{args.join(', ')}]"
120
+ end
121
+
71
122
  # bundle exec ./time.rb
72
123
  # :nocov:
73
124
  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.106.0'
6
+ VERSION = '0.108.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.106.0
4
+ version: 0.108.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vince Broz