relaton 3.1.15 → 3.1.17

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: 41a7f64e787b24723fa113edb1e212d200ab7eb382db19d54bc5551623b4d18a
4
- data.tar.gz: eeabf573cb7643a521426c129e0c1ada4c81ed2cf993dfbaa5bc0bb9b1423b59
3
+ metadata.gz: effcf0f04d9b075586f9ee71ddd815359b9b531d1a4536ca8407e1465be17411
4
+ data.tar.gz: f3305805c9aac14139c42a3e4fd0ffe972e60771f7a4cb64a86ff08c268f6c17
5
5
  SHA512:
6
- metadata.gz: 6d731f599c71306c4d2f155dcb2974b9aaa690cde0ceedb4dbeaff9be571b4f8df10bec0ba848cb858be2a140a2c77ae1c43249d1f64419b463ebb73a12d5db8
7
- data.tar.gz: 0f805d43da7544dbb09e14d34f89923fce20b1923562d16aa960a3ce002e87e85680521b64c45331d8b98e29f0c1b72fb28c329804ae5490027cd72d19f44d56
6
+ metadata.gz: 0d625297d44fc7ab8421a809ae76d6835220a0b1fe7af2faa8349b25a2a29db0e55f35e2a50c4a2aed5d3e894685b497fb5b29f945a89f5395f570b5b2085a2a
7
+ data.tar.gz: 7f84119ab99a8fbebca57de249d51a36c9a7d13936ffc07ea94af5517b6e372f9236eeeea9ebbec4e6969a0e07a632a145241487c8e203f36bb624dd7bc7686c
@@ -2,15 +2,49 @@ require "date"
2
2
 
3
3
  module Relaton
4
4
  module Bib
5
- # xs:date value type that always casts to ::Date, dropping any time and
6
- # timezone component. Without this, lutaml-model's built-in Date type
7
- # promotes inputs like "2018-04-15T00:00:00Z" to ::DateTime and serializes
8
- # them back as "2018-04-15Z" — valid xs:date, but not valid ISO 8601.
5
+ # Value type for validity-class dates that preserves the precision of
6
+ # the input: date-only input serializes as xs:date, input carrying a
7
+ # time serializes as ISO 8601 dateTime ("2010-10-10T12:21:00Z"). The
8
+ # bibdata schema requires dateTime whenever a time is present, so
9
+ # truncating to ::Date silently loses bibitem validity times
10
+ # (relaton#636; the truncating cast shipped in cf535198 for the Bipm
11
+ # static-file round-trip, whose date-only fixtures are unaffected).
9
12
  class PlainDate < Lutaml::Model::Type::Date
10
13
  def self.cast(value, options = {})
14
+ # String with a time component: parse as ::DateTime, keeping
15
+ # offset and precision (lutaml's Date cast truncates these).
16
+ return ::DateTime.parse(value) if value.is_a?(String) && value =~ /T\d{2}:\d{2}/
17
+ # ::DateTime objects already carry the caller's precision.
18
+ return value if value.is_a?(::DateTime)
19
+ # A string without a time component ("2018-04-15+05:30") is
20
+ # date-only regardless of its zone offset: keep xs:date.
11
21
  result = super
12
22
  result.is_a?(::DateTime) ? result.to_date : result
13
23
  end
24
+
25
+ def self.serialize(value, options = {})
26
+ case value
27
+ when ::DateTime
28
+ value.offset.zero? ? value.strftime("%FT%TZ") : value.xmlschema
29
+ when ::Date
30
+ value.iso8601
31
+ else
32
+ super
33
+ end
34
+ end
14
35
  end
15
36
  end
16
37
  end
38
+
39
+ # lutaml's format-serializer table resolves Date-typed attributes by
40
+ # walking the class hierarchy to the BASE Type::Date entry, whose static
41
+ # serialize truncates ::DateTime to "YYYY-MM-DDZ" — a subclass's serialize
42
+ # override is never consulted. Register this subclass explicitly so
43
+ # Validity#to_xml honors the precision-preserving serialization above
44
+ # (relaton#636).
45
+ if defined?(Lutaml::Xml::Type::Serializers)
46
+ Lutaml::Model::Type::Value.register_format_type_serializer(
47
+ :xml, Relaton::Bib::PlainDate,
48
+ to: ->(inst) { Relaton::Bib::PlainDate.serialize(inst.value) }
49
+ )
50
+ end
@@ -97,7 +97,12 @@ module Relaton
97
97
  hit = @pubid_memo[key]
98
98
  @pubid_memo.key?(key)
99
99
  end
100
- return hit if present
100
+ # Copy on handout (relaton#636): the memo stores one parse per
101
+ # [class, reference], and callers may mutate the identifier
102
+ # they receive (validity, extent, typed_stage). Handing out
103
+ # the memoized instance let one caller's mutation poison
104
+ # every later hit of the same reference.
105
+ return hit.dup if present
101
106
 
102
107
  parsed =
103
108
  begin
@@ -114,7 +119,7 @@ require_relative "../bib"
114
119
  @pubid_memo.shift while @pubid_memo.size >= MEMO_LIMIT
115
120
  @pubid_memo[key] = parsed
116
121
  end
117
- parsed
122
+ parsed&.dup
118
123
  end
119
124
  end
120
125
 
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "3.1.15".freeze
2
+ VERSION = "3.1.17".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.15
4
+ version: 3.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.