saxon-rb 0.7.1-java → 0.7.2-java

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: 5d368b655e7f8915a8adc9981dd8f2c3490be76f82307bd0e9620af0c864a244
4
- data.tar.gz: f95484360c8d7e364de5b72b0c5e1a3cd66f1e9a187c59bc1c7f30ce179724e5
3
+ metadata.gz: b28465f21f4fe169b356cbd1bce2d66ae1ae2a083d2ebe022963e1c3d229ef12
4
+ data.tar.gz: 82da6fa6d8570e791d17b3e46ec644200c7518019c9cec3c7804ad106ef2306e
5
5
  SHA512:
6
- metadata.gz: b37d08c73e14a7abd3efc3a7a5dbc1c1f18e2eda0ffb00d5e602d3331a7789c56a330e468d682e74ee9186a871eb9151d33c850fdfaa9322b60b45793217e135
7
- data.tar.gz: 32e296fa39be9f5ba45cf630bd88969bcca0ed8c1f244b81bfb48d22e8133e4dccfb2b1f2c85beed5e3af8a7d52512492859f9ad17b2ddced988680a085c2b7c
6
+ metadata.gz: 83cc23c8755cb8843cb8f44afd948582339e26b492ff7eb505badbb9f727f8a98d622b1adf501f06f77ab4554ba40b5e40ead8554a7bd06caf20ab570a7765fb
7
+ data.tar.gz: '09db9b468b5ce5d21bc48c6602ec6a93e1a0ad61b55a550556cff4804912848a0947904d6fa0ff19e9a8cb92cb847e61615dc435c15147e43b197a8fa5d3d6e0'
@@ -6,8 +6,49 @@ require_relative 'item_type/value_to_ruby'
6
6
  module Saxon
7
7
  # Represent XDM types abstractly
8
8
  class ItemType
9
- # Error raised when a Ruby class has no equivalent XDM type to be converted
10
- # into
9
+ # lazy-loading Hash so we can avoid eager-loading saxon Jars, which prevents
10
+ # using external Saxon Jars unless the user is more careful than they should
11
+ # have to be.
12
+ class LazyReadOnlyHash
13
+ include Enumerable
14
+
15
+ attr_reader :loaded_hash, :load_mutex, :init_block
16
+ private :loaded_hash, :load_mutex, :init_block
17
+
18
+ def initialize(&init_block)
19
+ @init_block = init_block
20
+ @load_mutex = Mutex.new
21
+ @loaded_hash = nil
22
+ end
23
+
24
+ def [](key)
25
+ ensure_loaded!
26
+ loaded_hash[key]
27
+ end
28
+
29
+ def fetch(*args, &block)
30
+ ensure_loaded!
31
+ loaded_hash.fetch(*args, &block)
32
+ end
33
+
34
+ def each(&block)
35
+ ensure_loaded!
36
+ loaded_hash.each(&block)
37
+ end
38
+
39
+ private
40
+
41
+ def ensure_loaded!
42
+ return true unless loaded_hash.nil?
43
+ load_mutex.synchronize do
44
+ return true unless loaded_hash.nil?
45
+ @loaded_hash = init_block.call
46
+ end
47
+ end
48
+ end
49
+
50
+ # Error raised when a Ruby class has no equivalent XDM type to
51
+ # be converted into
11
52
  class UnmappedRubyTypeError < StandardError
12
53
  def initialize(class_name)
13
54
  @class_name = class_name
@@ -54,85 +95,89 @@ module Saxon
54
95
  }.freeze
55
96
 
56
97
  # A mapping of QNames to XDM type constants
57
- QNAME_MAPPING = Hash[{
58
- 'anyAtomicType' => :ANY_ATOMIC_VALUE,
59
- 'anyURI' => :ANY_URI,
60
- 'base64Binary' => :BASE64_BINARY,
61
- 'boolean' => :BOOLEAN,
62
- 'byte' => :BYTE,
63
- 'date' => :DATE,
64
- 'dateTime' => :DATE_TIME,
65
- 'dateTimeStamp' => :DATE_TIME_STAMP,
66
- 'dayTimeDuration' => :DAY_TIME_DURATION,
67
- 'decimal' => :DECIMAL,
68
- 'double' => :DOUBLE,
69
- 'duration' => :DURATION,
70
- 'ENTITY' => :ENTITY,
71
- 'float' => :FLOAT,
72
- 'gDay' => :G_DAY,
73
- 'gMonth' => :G_MONTH,
74
- 'gMonthDay' => :G_MONTH_DAY,
75
- 'gYear' => :G_YEAR,
76
- 'gYearMonth' => :G_YEAR_MONTH,
77
- 'hexBinary' => :HEX_BINARY,
78
- 'ID' => :ID,
79
- 'IDREF' => :IDREF,
80
- 'int' => :INT,
81
- 'integer' => :INTEGER,
82
- 'language' => :LANGUAGE,
83
- 'long' => :LONG,
84
- 'Name' => :NAME,
85
- 'NCName' => :NCNAME,
86
- 'negativeInteger' => :NEGATIVE_INTEGER,
87
- 'NMTOKEN' => :NMTOKEN,
88
- 'nonNegativeInteger' => :NON_NEGATIVE_INTEGER,
89
- 'nonPositiveInteger' => :NON_POSITIVE_INTEGER,
90
- 'normalizedString' => :NORMALIZED_STRING,
91
- 'NOTATION' => :NOTATION,
92
- 'numeric' => :NUMERIC,
93
- 'positiveInteger' => :POSITIVE_INTEGER,
94
- 'QName' => :QNAME,
95
- 'short' => :SHORT,
96
- 'string' => :STRING,
97
- 'time' => :TIME,
98
- 'token' => :TOKEN,
99
- 'unsignedByte' => :UNSIGNED_BYTE,
100
- 'unsignedInt' => :UNSIGNED_INT,
101
- 'unsignedLong' => :UNSIGNED_LONG,
102
- 'unsignedShort' => :UNSIGNED_SHORT,
103
- 'untypedAtomic' => :UNTYPED_ATOMIC,
104
- 'yearMonthDuration' => :YEAR_MONTH_DURATION
105
- }.map { |local_name, constant|
106
- qname = Saxon::QName.create({
107
- prefix: 'xs', uri: 'http://www.w3.org/2001/XMLSchema',
108
- local_name: local_name
109
- })
110
- [qname, constant]
111
- }].freeze
98
+ QNAME_MAPPING = LazyReadOnlyHash.new do
99
+ {
100
+ 'anyAtomicType' => :ANY_ATOMIC_VALUE,
101
+ 'anyURI' => :ANY_URI,
102
+ 'base64Binary' => :BASE64_BINARY,
103
+ 'boolean' => :BOOLEAN,
104
+ 'byte' => :BYTE,
105
+ 'date' => :DATE,
106
+ 'dateTime' => :DATE_TIME,
107
+ 'dateTimeStamp' => :DATE_TIME_STAMP,
108
+ 'dayTimeDuration' => :DAY_TIME_DURATION,
109
+ 'decimal' => :DECIMAL,
110
+ 'double' => :DOUBLE,
111
+ 'duration' => :DURATION,
112
+ 'ENTITY' => :ENTITY,
113
+ 'float' => :FLOAT,
114
+ 'gDay' => :G_DAY,
115
+ 'gMonth' => :G_MONTH,
116
+ 'gMonthDay' => :G_MONTH_DAY,
117
+ 'gYear' => :G_YEAR,
118
+ 'gYearMonth' => :G_YEAR_MONTH,
119
+ 'hexBinary' => :HEX_BINARY,
120
+ 'ID' => :ID,
121
+ 'IDREF' => :IDREF,
122
+ 'int' => :INT,
123
+ 'integer' => :INTEGER,
124
+ 'language' => :LANGUAGE,
125
+ 'long' => :LONG,
126
+ 'Name' => :NAME,
127
+ 'NCName' => :NCNAME,
128
+ 'negativeInteger' => :NEGATIVE_INTEGER,
129
+ 'NMTOKEN' => :NMTOKEN,
130
+ 'nonNegativeInteger' => :NON_NEGATIVE_INTEGER,
131
+ 'nonPositiveInteger' => :NON_POSITIVE_INTEGER,
132
+ 'normalizedString' => :NORMALIZED_STRING,
133
+ 'NOTATION' => :NOTATION,
134
+ 'numeric' => :NUMERIC,
135
+ 'positiveInteger' => :POSITIVE_INTEGER,
136
+ 'QName' => :QNAME,
137
+ 'short' => :SHORT,
138
+ 'string' => :STRING,
139
+ 'time' => :TIME,
140
+ 'token' => :TOKEN,
141
+ 'unsignedByte' => :UNSIGNED_BYTE,
142
+ 'unsignedInt' => :UNSIGNED_INT,
143
+ 'unsignedLong' => :UNSIGNED_LONG,
144
+ 'unsignedShort' => :UNSIGNED_SHORT,
145
+ 'untypedAtomic' => :UNTYPED_ATOMIC,
146
+ 'yearMonthDuration' => :YEAR_MONTH_DURATION
147
+ }.map { |local_name, constant|
148
+ qname = Saxon::QName.create({
149
+ prefix: 'xs', uri: 'http://www.w3.org/2001/XMLSchema',
150
+ local_name: local_name
151
+ })
152
+ [qname, constant]
153
+ }.to_h.freeze
154
+ end
112
155
 
113
156
  # A mapping of type names/QNames to XDM type constants
114
- STR_MAPPING = {
115
- 'array(*)' => :ANY_ARRAY,
116
- 'item()' => :ANY_ITEM,
117
- 'map(*)' => :ANY_MAP,
118
- 'node()' => :ANY_NODE
119
- }.merge(
120
- Hash[QNAME_MAPPING.map { |qname, v| [qname.to_s, v] }]
121
- ).freeze
157
+ STR_MAPPING = LazyReadOnlyHash.new do
158
+ {
159
+ 'array(*)' => :ANY_ARRAY,
160
+ 'item()' => :ANY_ITEM,
161
+ 'map(*)' => :ANY_MAP,
162
+ 'node()' => :ANY_NODE
163
+ }.merge(
164
+ Hash[QNAME_MAPPING.map { |qname, v| [qname.to_s, v] }]
165
+ ).freeze
166
+ end
122
167
 
123
168
  # convertors to generate lexical strings for a given {ItemType}, as a hash keyed on the ItemType
124
- ATOMIC_VALUE_LEXICAL_STRING_CONVERTORS = Hash[
169
+ ATOMIC_VALUE_LEXICAL_STRING_CONVERTORS = LazyReadOnlyHash.new do
125
170
  LexicalStringConversion::Convertors.constants.map { |const|
126
171
  [S9API::ItemType.const_get(const), LexicalStringConversion::Convertors.const_get(const)]
127
- }
128
- ].freeze
172
+ }.to_h.freeze
173
+ end
129
174
 
130
175
  # convertors from {XDM::AtomicValue} to a ruby primitve value, as a hash keyed on the ItemType
131
- ATOMIC_VALUE_TO_RUBY_CONVERTORS = Hash[
176
+ ATOMIC_VALUE_TO_RUBY_CONVERTORS = LazyReadOnlyHash.new do
132
177
  ValueToRuby::Convertors.constants.map { |const|
133
178
  [S9API::ItemType.const_get(const), ValueToRuby::Convertors.const_get(const)]
134
- }
135
- ].freeze
179
+ }.to_h.freeze
180
+ end
136
181
 
137
182
  class << self
138
183
  # Get an appropriate {ItemType} for a Ruby type or given a type name as a
@@ -4,6 +4,6 @@ module Saxon
4
4
  # Provides the saxon-rb and underlying Saxon library versions
5
5
  module Version
6
6
  # The version of the saxon-rb gem (not of Saxon itself)
7
- WRAPPER = "0.7.1"
7
+ WRAPPER = "0.7.2"
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saxon-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: java
6
6
  authors:
7
7
  - Matt Patterson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-24 00:00:00.000000000 Z
11
+ date: 2020-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement