sourced-message 0.5.1 → 0.5.2
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -1
- data/lib/sourced/message.rb +20 -7
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 80569ac57d96516a6efd3bd8c09ef862a7c48d9e661fb82404476608995c6350
|
|
4
|
+
data.tar.gz: a480b3c5007cab3ad87f242a5828a548e294150ef2ad65b5afdc2dc98d53423c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bae04d8962a7e19f8f21985b674b29e0ddb90987934a51504e8eeba4e357b7925b983c4e9cee10b719b0598ecae963af0dccbd79efb0679a44ace463184e6c37
|
|
7
|
+
data.tar.gz: df823ccc2eab96eaddba05255f0776b069dfa57004bb58f2337f9de8aeedd29fe3d30ed04ed7e72ac0211c0e6195110cb19bbd735014fefd76013aa975349f24
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
- `Message#at` with a duration string (`'1h30m'`) raised `ArgumentError` ("Cannot
|
|
4
|
+
determine timezone from \"BST\"") in the hour the clocks go back. The duration's
|
|
5
|
+
seconds are now added to `Time.now`, exactly. Durations in months or years, which
|
|
6
|
+
aren't a fixed number of seconds, raise `ArgumentError`.
|
|
3
7
|
- `Message::Registry` raises `DuplicateTypeError` when two classes with different names
|
|
4
8
|
claim one type string, instead of silently replacing the registered class. Registering
|
|
5
9
|
a type again is still allowed when the names are equal (a code reloader redefining a
|
data/README.md
CHANGED
|
@@ -372,10 +372,11 @@ Scheduling a message into the past raises `Sourced::Message::PastMessageDateErro
|
|
|
372
372
|
msg.at(Time.now - 60) # => raises Sourced::Message::PastMessageDateError
|
|
373
373
|
```
|
|
374
374
|
|
|
375
|
-
Passing a string that isn't a duration (e.g. an absolute date) raises `ArgumentError
|
|
375
|
+
Passing a string that isn't a duration (e.g. an absolute date) raises `ArgumentError`, as does a duration in months or years, which vary in length (give days instead):
|
|
376
376
|
|
|
377
377
|
```ruby
|
|
378
378
|
msg.in('2026-12-31T10:00:00') # => raises ArgumentError
|
|
379
|
+
msg.in('1M') # => raises ArgumentError; msg.in('30d') instead
|
|
379
380
|
```
|
|
380
381
|
|
|
381
382
|
### Pattern matching with `case`/`when`
|
data/lib/sourced/message.rb
CHANGED
|
@@ -22,7 +22,7 @@ module Sourced
|
|
|
22
22
|
# +Sourced::Message.registry[type]+ resolves a type registered under any
|
|
23
23
|
# subclass. Resolve from this root to see the whole tree.
|
|
24
24
|
class Message < Plumb::Types::Data
|
|
25
|
-
VERSION = '0.5.
|
|
25
|
+
VERSION = '0.5.2'
|
|
26
26
|
|
|
27
27
|
EMPTY_ARRAY = [].freeze
|
|
28
28
|
|
|
@@ -286,7 +286,9 @@ module Sourced
|
|
|
286
286
|
# target.
|
|
287
287
|
# - +Integer+ — interpreted as seconds; added to +Time.now+.
|
|
288
288
|
# - +String+ — parsed via +Fugit.parse_duration+ as a duration (e.g.
|
|
289
|
-
# +'5m'+, +'1h30m'+, +'PT5M'+) and added to
|
|
289
|
+
# +'5m'+, +'1h30m'+, +'PT5M'+), up to weeks, and its seconds added to
|
|
290
|
+
# +Time.now+. Months and years aren't a fixed number of seconds, so
|
|
291
|
+
# they raise +ArgumentError+.
|
|
290
292
|
#
|
|
291
293
|
# Raises {PastMessageDateError} when the resolved target is
|
|
292
294
|
# before +created_at+.
|
|
@@ -295,11 +297,7 @@ module Sourced
|
|
|
295
297
|
when Integer
|
|
296
298
|
Time.now + value
|
|
297
299
|
when String
|
|
298
|
-
|
|
299
|
-
raise ArgumentError,
|
|
300
|
-
"Message#at: String argument must be an ISO8601 / Fugit duration " \
|
|
301
|
-
"(e.g. '5m', 'PT1H30M'); got #{value.inspect}"
|
|
302
|
-
parsed.add_to_time(Time.now).to_local_time
|
|
300
|
+
Time.now + duration_seconds(value)
|
|
303
301
|
else
|
|
304
302
|
value
|
|
305
303
|
end
|
|
@@ -375,6 +373,21 @@ module Sourced
|
|
|
375
373
|
attrs[:causation_id] = attrs[:id] unless attrs[:causation_id]
|
|
376
374
|
attrs
|
|
377
375
|
end
|
|
376
|
+
|
|
377
|
+
# A duration string's seconds, up to weeks.
|
|
378
|
+
def duration_seconds(value)
|
|
379
|
+
duration = Fugit.parse_duration(value) or
|
|
380
|
+
raise ArgumentError,
|
|
381
|
+
"Message#at: String argument must be an ISO8601 / Fugit duration " \
|
|
382
|
+
"(e.g. '5m', 'PT1H30M'); got #{value.inspect}"
|
|
383
|
+
if duration.h.key?(:yea) || duration.h.key?(:mon)
|
|
384
|
+
raise ArgumentError,
|
|
385
|
+
"Message#at: can't delay by months or years, which vary in length; " \
|
|
386
|
+
"give days (e.g. '30d'); got #{value.inspect}"
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
duration.to_sec
|
|
390
|
+
end
|
|
378
391
|
end
|
|
379
392
|
|
|
380
393
|
class Command < Message; end
|