shale 0.3.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +37 -0
- data/README.md +398 -41
- data/exe/shaleb +108 -36
- data/lib/shale/adapter/nokogiri/document.rb +97 -0
- data/lib/shale/adapter/nokogiri/node.rb +100 -0
- data/lib/shale/adapter/nokogiri.rb +11 -151
- data/lib/shale/adapter/ox/document.rb +90 -0
- data/lib/shale/adapter/ox/node.rb +97 -0
- data/lib/shale/adapter/ox.rb +9 -134
- data/lib/shale/adapter/rexml/document.rb +98 -0
- data/lib/shale/adapter/rexml/node.rb +99 -0
- data/lib/shale/adapter/rexml.rb +9 -150
- data/lib/shale/adapter/toml_rb.rb +34 -0
- data/lib/shale/attribute.rb +6 -0
- data/lib/shale/error.rb +56 -0
- data/lib/shale/mapper.rb +67 -13
- data/lib/shale/mapping/descriptor/xml.rb +10 -1
- data/lib/shale/mapping/dict.rb +18 -0
- data/lib/shale/mapping/xml.rb +40 -5
- data/lib/shale/schema/compiler/boolean.rb +21 -0
- data/lib/shale/schema/compiler/complex.rb +88 -0
- data/lib/shale/schema/compiler/date.rb +21 -0
- data/lib/shale/schema/compiler/float.rb +21 -0
- data/lib/shale/schema/compiler/integer.rb +21 -0
- data/lib/shale/schema/compiler/property.rb +70 -0
- data/lib/shale/schema/compiler/string.rb +21 -0
- data/lib/shale/schema/compiler/time.rb +21 -0
- data/lib/shale/schema/compiler/value.rb +21 -0
- data/lib/shale/schema/compiler/xml_complex.rb +50 -0
- data/lib/shale/schema/compiler/xml_property.rb +73 -0
- data/lib/shale/schema/json_compiler.rb +331 -0
- data/lib/shale/schema/{json → json_generator}/base.rb +2 -2
- data/lib/shale/schema/{json → json_generator}/boolean.rb +1 -1
- data/lib/shale/schema/{json → json_generator}/collection.rb +2 -2
- data/lib/shale/schema/{json → json_generator}/date.rb +1 -1
- data/lib/shale/schema/{json → json_generator}/float.rb +1 -1
- data/lib/shale/schema/{json → json_generator}/integer.rb +1 -1
- data/lib/shale/schema/{json → json_generator}/object.rb +5 -2
- data/lib/shale/schema/{json → json_generator}/ref.rb +1 -1
- data/lib/shale/schema/{json → json_generator}/schema.rb +6 -4
- data/lib/shale/schema/{json → json_generator}/string.rb +1 -1
- data/lib/shale/schema/{json → json_generator}/time.rb +1 -1
- data/lib/shale/schema/json_generator/value.rb +23 -0
- data/lib/shale/schema/{json.rb → json_generator.rb} +36 -36
- data/lib/shale/schema/xml_compiler.rb +919 -0
- data/lib/shale/schema/{xml → xml_generator}/attribute.rb +1 -1
- data/lib/shale/schema/{xml → xml_generator}/complex_type.rb +5 -2
- data/lib/shale/schema/{xml → xml_generator}/element.rb +1 -1
- data/lib/shale/schema/{xml → xml_generator}/import.rb +1 -1
- data/lib/shale/schema/{xml → xml_generator}/ref_attribute.rb +1 -1
- data/lib/shale/schema/{xml → xml_generator}/ref_element.rb +1 -1
- data/lib/shale/schema/{xml → xml_generator}/schema.rb +5 -5
- data/lib/shale/schema/{xml → xml_generator}/typed_attribute.rb +1 -1
- data/lib/shale/schema/{xml → xml_generator}/typed_element.rb +1 -1
- data/lib/shale/schema/{xml.rb → xml_generator.rb} +25 -26
- data/lib/shale/schema.rb +44 -5
- data/lib/shale/type/{composite.rb → complex.rb} +156 -51
- data/lib/shale/type/value.rb +31 -2
- data/lib/shale/utils.rb +42 -7
- data/lib/shale/version.rb +1 -1
- data/lib/shale.rb +22 -19
- data/shale.gemspec +3 -3
- metadata +50 -29
@@ -1,18 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../error'
|
3
4
|
require_relative 'value'
|
4
5
|
|
5
6
|
module Shale
|
6
7
|
module Type
|
7
|
-
# Build
|
8
|
+
# Build complex object. Don't use it directly.
|
8
9
|
# It serves as a base type class for @see Shale::Mapper
|
9
10
|
#
|
10
11
|
# @api private
|
11
|
-
class
|
12
|
+
class Complex < Value
|
12
13
|
class << self
|
13
|
-
%i[hash json yaml].each do |format|
|
14
|
+
%i[hash json yaml toml].each do |format|
|
14
15
|
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
15
|
-
# Convert Hash to Object using Hash/JSON/YAML mapping
|
16
|
+
# Convert Hash to Object using Hash/JSON/YAML/TOML mapping
|
16
17
|
#
|
17
18
|
# @param [Hash] hash Hash to convert
|
18
19
|
#
|
@@ -20,7 +21,12 @@ module Shale
|
|
20
21
|
#
|
21
22
|
# @api public
|
22
23
|
def of_#{format}(hash)
|
23
|
-
instance = new
|
24
|
+
instance = model.new
|
25
|
+
|
26
|
+
attributes
|
27
|
+
.values
|
28
|
+
.select { |attr| attr.default }
|
29
|
+
.each { |attr| instance.send(attr.setter, attr.default.call) }
|
24
30
|
|
25
31
|
mapping_keys = #{format}_mapping.keys
|
26
32
|
|
@@ -29,24 +35,21 @@ module Shale
|
|
29
35
|
next unless mapping
|
30
36
|
|
31
37
|
if mapping.method_from
|
32
|
-
|
38
|
+
new.send(mapping.method_from, instance, value)
|
33
39
|
else
|
34
40
|
attribute = attributes[mapping.attribute]
|
35
41
|
next unless attribute
|
36
42
|
|
37
43
|
if value.nil?
|
38
|
-
instance.
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
if attribute.collection?
|
44
|
+
instance.send(attribute.setter, nil)
|
45
|
+
elsif attribute.collection?
|
43
46
|
[*value].each do |val|
|
44
47
|
val = val ? attribute.type.of_#{format}(val) : val
|
45
|
-
instance.
|
48
|
+
instance.send(attribute.name) << attribute.type.cast(val)
|
46
49
|
end
|
47
50
|
else
|
48
51
|
val = attribute.type.of_#{format}(value)
|
49
|
-
instance.
|
52
|
+
instance.send(attribute.setter, attribute.type.cast(val))
|
50
53
|
end
|
51
54
|
end
|
52
55
|
end
|
@@ -54,31 +57,35 @@ module Shale
|
|
54
57
|
instance
|
55
58
|
end
|
56
59
|
|
57
|
-
# Convert Object to Hash using Hash/JSON/YAML mapping
|
60
|
+
# Convert Object to Hash using Hash/JSON/YAML/TOML mapping
|
61
|
+
#
|
62
|
+
# @param [any] instance Object to convert
|
58
63
|
#
|
59
|
-
# @
|
64
|
+
# @raise [IncorrectModelError]
|
60
65
|
#
|
61
66
|
# @return [Hash]
|
62
67
|
#
|
63
68
|
# @api public
|
64
69
|
def as_#{format}(instance)
|
70
|
+
unless instance.is_a?(model)
|
71
|
+
msg = "argument is a '\#{instance.class}' but should be a '\#{model}'"
|
72
|
+
raise IncorrectModelError, msg
|
73
|
+
end
|
74
|
+
|
65
75
|
hash = {}
|
66
76
|
|
67
|
-
|
77
|
+
#{format}_mapping.keys.each_value do |mapping|
|
68
78
|
if mapping.method_to
|
69
|
-
hash[mapping.name] =
|
79
|
+
hash[mapping.name] = new.send(mapping.method_to, instance)
|
70
80
|
else
|
71
|
-
attribute =
|
81
|
+
attribute = attributes[mapping.attribute]
|
72
82
|
next unless attribute
|
73
83
|
|
74
|
-
value = instance.
|
84
|
+
value = instance.send(attribute.name)
|
75
85
|
|
76
86
|
if value.nil?
|
77
87
|
hash[mapping.name] = nil
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
if attribute.collection?
|
88
|
+
elsif attribute.collection?
|
82
89
|
hash[mapping.name] = [*value].map do |v|
|
83
90
|
v ? attribute.type.as_#{format}(v) : v
|
84
91
|
end
|
@@ -142,6 +149,30 @@ module Shale
|
|
142
149
|
Shale.yaml_adapter.dump(as_yaml(instance))
|
143
150
|
end
|
144
151
|
|
152
|
+
# Convert TOML to Object
|
153
|
+
#
|
154
|
+
# @param [String] toml TOML to convert
|
155
|
+
#
|
156
|
+
# @return [Shale::Mapper]
|
157
|
+
#
|
158
|
+
# @api public
|
159
|
+
def from_toml(toml)
|
160
|
+
validate_toml_adapter
|
161
|
+
of_toml(Shale.toml_adapter.load(toml))
|
162
|
+
end
|
163
|
+
|
164
|
+
# Convert Object to TOML
|
165
|
+
#
|
166
|
+
# @param [Shale::Mapper] instance Object to convert
|
167
|
+
#
|
168
|
+
# @return [String]
|
169
|
+
#
|
170
|
+
# @api public
|
171
|
+
def to_toml(instance)
|
172
|
+
validate_toml_adapter
|
173
|
+
Shale.toml_adapter.dump(as_toml(instance))
|
174
|
+
end
|
175
|
+
|
145
176
|
# Convert XML document to Object
|
146
177
|
#
|
147
178
|
# @param [Shale::Adapter::<XML adapter>::Node] xml XML to convert
|
@@ -150,31 +181,43 @@ module Shale
|
|
150
181
|
#
|
151
182
|
# @api public
|
152
183
|
def of_xml(element)
|
153
|
-
instance = new
|
184
|
+
instance = model.new
|
185
|
+
|
186
|
+
attributes
|
187
|
+
.values
|
188
|
+
.select { |attr| attr.default }
|
189
|
+
.each { |attr| instance.send(attr.setter, attr.default.call) }
|
154
190
|
|
155
191
|
element.attributes.each do |key, value|
|
156
192
|
mapping = xml_mapping.attributes[key.to_s]
|
157
193
|
next unless mapping
|
158
194
|
|
159
195
|
if mapping.method_from
|
160
|
-
|
196
|
+
new.send(mapping.method_from, instance, value)
|
161
197
|
else
|
162
198
|
attribute = attributes[mapping.attribute]
|
163
199
|
next unless attribute
|
164
200
|
|
165
201
|
if attribute.collection?
|
166
|
-
instance.
|
202
|
+
instance.send(attribute.name) << attribute.type.cast(value)
|
167
203
|
else
|
168
|
-
instance.
|
204
|
+
instance.send(attribute.setter, attribute.type.cast(value))
|
169
205
|
end
|
170
206
|
end
|
171
207
|
end
|
172
208
|
|
173
|
-
|
174
|
-
|
209
|
+
content_mapping = xml_mapping.content
|
210
|
+
|
211
|
+
if content_mapping
|
212
|
+
if content_mapping.method_from
|
213
|
+
new.send(content_mapping.method_from, instance, element)
|
214
|
+
else
|
215
|
+
attribute = attributes[content_mapping.attribute]
|
175
216
|
|
176
|
-
|
177
|
-
|
217
|
+
if attribute
|
218
|
+
value = attribute.type.of_xml(element)
|
219
|
+
instance.send(attribute.setter, attribute.type.cast(value))
|
220
|
+
end
|
178
221
|
end
|
179
222
|
end
|
180
223
|
|
@@ -183,16 +226,17 @@ module Shale
|
|
183
226
|
next unless mapping
|
184
227
|
|
185
228
|
if mapping.method_from
|
186
|
-
|
229
|
+
new.send(mapping.method_from, instance, node)
|
187
230
|
else
|
188
231
|
attribute = attributes[mapping.attribute]
|
189
232
|
next unless attribute
|
190
233
|
|
234
|
+
value = attribute.type.of_xml(node)
|
235
|
+
|
191
236
|
if attribute.collection?
|
192
|
-
|
193
|
-
instance.public_send(attribute.name) << attribute.type.cast(value)
|
237
|
+
instance.send(attribute.name) << attribute.type.cast(value)
|
194
238
|
else
|
195
|
-
instance.
|
239
|
+
instance.send(attribute.setter, attribute.type.cast(value))
|
196
240
|
end
|
197
241
|
end
|
198
242
|
end
|
@@ -204,23 +248,33 @@ module Shale
|
|
204
248
|
#
|
205
249
|
# @param [String] xml XML to convert
|
206
250
|
#
|
251
|
+
# @raise [AdapterError]
|
252
|
+
#
|
207
253
|
# @return [Shale::Mapper]
|
208
254
|
#
|
209
255
|
# @api public
|
210
256
|
def from_xml(xml)
|
257
|
+
validate_xml_adapter
|
211
258
|
of_xml(Shale.xml_adapter.load(xml))
|
212
259
|
end
|
213
260
|
|
214
261
|
# Convert Object to XML document
|
215
262
|
#
|
216
|
-
# @param [
|
263
|
+
# @param [any] instance Object to convert
|
217
264
|
# @param [String, nil] node_name XML node name
|
218
265
|
# @param [Shale::Adapter::<xml adapter>::Document, nil] doc Object to convert
|
219
266
|
#
|
267
|
+
# @raise [IncorrectModelError]
|
268
|
+
#
|
220
269
|
# @return [::REXML::Document, ::Nokogiri::Document, ::Ox::Document]
|
221
270
|
#
|
222
271
|
# @api public
|
223
|
-
def as_xml(instance, node_name = nil, doc = nil)
|
272
|
+
def as_xml(instance, node_name = nil, doc = nil, _cdata = nil)
|
273
|
+
unless instance.is_a?(model)
|
274
|
+
msg = "argument is a '#{instance.class}' but should be a '#{model}'"
|
275
|
+
raise IncorrectModelError, msg
|
276
|
+
end
|
277
|
+
|
224
278
|
unless doc
|
225
279
|
doc = Shale.xml_adapter.create_document
|
226
280
|
doc.add_element(doc.doc, as_xml(instance, xml_mapping.prefixed_root, doc))
|
@@ -228,16 +282,20 @@ module Shale
|
|
228
282
|
end
|
229
283
|
|
230
284
|
element = doc.create_element(node_name)
|
231
|
-
|
285
|
+
|
286
|
+
doc.add_namespace(
|
287
|
+
xml_mapping.default_namespace.prefix,
|
288
|
+
xml_mapping.default_namespace.name
|
289
|
+
)
|
232
290
|
|
233
291
|
xml_mapping.attributes.each_value do |mapping|
|
234
292
|
if mapping.method_to
|
235
|
-
|
293
|
+
new.send(mapping.method_to, instance, element, doc)
|
236
294
|
else
|
237
|
-
attribute =
|
295
|
+
attribute = attributes[mapping.attribute]
|
238
296
|
next unless attribute
|
239
297
|
|
240
|
-
value = instance.
|
298
|
+
value = instance.send(attribute.name)
|
241
299
|
next if value.nil?
|
242
300
|
|
243
301
|
doc.add_namespace(mapping.namespace.prefix, mapping.namespace.name)
|
@@ -245,23 +303,36 @@ module Shale
|
|
245
303
|
end
|
246
304
|
end
|
247
305
|
|
248
|
-
|
249
|
-
|
306
|
+
content_mapping = xml_mapping.content
|
307
|
+
|
308
|
+
if content_mapping
|
309
|
+
if content_mapping.method_to
|
310
|
+
new.send(content_mapping.method_to, instance, element, doc)
|
311
|
+
else
|
312
|
+
attribute = attributes[content_mapping.attribute]
|
250
313
|
|
251
|
-
|
252
|
-
|
253
|
-
|
314
|
+
if attribute
|
315
|
+
value = instance.send(attribute.name)
|
316
|
+
|
317
|
+
# rubocop:disable Metrics/BlockNesting
|
318
|
+
if content_mapping.cdata
|
319
|
+
doc.create_cdata(value.to_s, element)
|
320
|
+
else
|
321
|
+
doc.add_text(element, value.to_s)
|
322
|
+
end
|
323
|
+
# rubocop:enable Metrics/BlockNesting
|
324
|
+
end
|
254
325
|
end
|
255
326
|
end
|
256
327
|
|
257
328
|
xml_mapping.elements.each_value do |mapping|
|
258
329
|
if mapping.method_to
|
259
|
-
|
330
|
+
new.send(mapping.method_to, instance, element, doc)
|
260
331
|
else
|
261
|
-
attribute =
|
332
|
+
attribute = attributes[mapping.attribute]
|
262
333
|
next unless attribute
|
263
334
|
|
264
|
-
value = instance.
|
335
|
+
value = instance.send(attribute.name)
|
265
336
|
next if value.nil?
|
266
337
|
|
267
338
|
doc.add_namespace(mapping.namespace.prefix, mapping.namespace.name)
|
@@ -269,10 +340,12 @@ module Shale
|
|
269
340
|
if attribute.collection?
|
270
341
|
[*value].each do |v|
|
271
342
|
next if v.nil?
|
272
|
-
|
343
|
+
child = attribute.type.as_xml(v, mapping.prefixed_name, doc, mapping.cdata)
|
344
|
+
doc.add_element(element, child)
|
273
345
|
end
|
274
346
|
else
|
275
|
-
|
347
|
+
child = attribute.type.as_xml(value, mapping.prefixed_name, doc, mapping.cdata)
|
348
|
+
doc.add_element(element, child)
|
276
349
|
end
|
277
350
|
end
|
278
351
|
end
|
@@ -285,12 +358,35 @@ module Shale
|
|
285
358
|
# @param [Shale::Mapper] instance Object to convert
|
286
359
|
# @param [Array<Symbol>] options
|
287
360
|
#
|
361
|
+
# @raise [AdapterError]
|
362
|
+
#
|
288
363
|
# @return [String]
|
289
364
|
#
|
290
365
|
# @api public
|
291
366
|
def to_xml(instance, *options)
|
367
|
+
validate_xml_adapter
|
292
368
|
Shale.xml_adapter.dump(as_xml(instance), *options)
|
293
369
|
end
|
370
|
+
|
371
|
+
private
|
372
|
+
|
373
|
+
# Validate TOML adapter
|
374
|
+
#
|
375
|
+
# @raise [AdapterError]
|
376
|
+
#
|
377
|
+
# @api private
|
378
|
+
def validate_toml_adapter
|
379
|
+
raise AdapterError, TOML_ADAPTER_NOT_SET_MESSAGE unless Shale.toml_adapter
|
380
|
+
end
|
381
|
+
|
382
|
+
# Validate XML adapter
|
383
|
+
#
|
384
|
+
# @raise [AdapterError]
|
385
|
+
#
|
386
|
+
# @api private
|
387
|
+
def validate_xml_adapter
|
388
|
+
raise AdapterError, XML_ADAPTER_NOT_SET_MESSAGE unless Shale.xml_adapter
|
389
|
+
end
|
294
390
|
end
|
295
391
|
|
296
392
|
# Convert Object to Hash
|
@@ -322,6 +418,15 @@ module Shale
|
|
322
418
|
self.class.to_yaml(self)
|
323
419
|
end
|
324
420
|
|
421
|
+
# Convert Object to TOML
|
422
|
+
#
|
423
|
+
# @return [String]
|
424
|
+
#
|
425
|
+
# @api public
|
426
|
+
def to_toml
|
427
|
+
self.class.to_toml(self)
|
428
|
+
end
|
429
|
+
|
325
430
|
# Convert Object to XML
|
326
431
|
#
|
327
432
|
# @param [Array<Symbol>] options
|
data/lib/shale/type/value.rb
CHANGED
@@ -89,6 +89,28 @@ module Shale
|
|
89
89
|
value
|
90
90
|
end
|
91
91
|
|
92
|
+
# Extract value from TOML document
|
93
|
+
#
|
94
|
+
# @param [any] value
|
95
|
+
#
|
96
|
+
# @return [any]
|
97
|
+
#
|
98
|
+
# @api private
|
99
|
+
def of_toml(value)
|
100
|
+
value
|
101
|
+
end
|
102
|
+
|
103
|
+
# Convert value to form accepted by TOML document
|
104
|
+
#
|
105
|
+
# @param [any] value
|
106
|
+
#
|
107
|
+
# @return [any]
|
108
|
+
#
|
109
|
+
# @api private
|
110
|
+
def as_toml(value)
|
111
|
+
value
|
112
|
+
end
|
113
|
+
|
92
114
|
# Extract value from XML document
|
93
115
|
#
|
94
116
|
# @param [Shale::Adapter::<XML adapter>::Node] value
|
@@ -116,11 +138,18 @@ module Shale
|
|
116
138
|
# @param [#to_s] value Value to convert to XML
|
117
139
|
# @param [String] name Name of the element
|
118
140
|
# @param [Shale::Adapter::<XML adapter>::Document] doc Document
|
141
|
+
# @param [true, false] cdata
|
119
142
|
#
|
120
143
|
# @api private
|
121
|
-
def as_xml(value, name, doc)
|
144
|
+
def as_xml(value, name, doc, cdata = false)
|
122
145
|
element = doc.create_element(name)
|
123
|
-
|
146
|
+
|
147
|
+
if cdata
|
148
|
+
doc.create_cdata(as_xml_value(value), element)
|
149
|
+
else
|
150
|
+
doc.add_text(element, as_xml_value(value))
|
151
|
+
end
|
152
|
+
|
124
153
|
element
|
125
154
|
end
|
126
155
|
end
|
data/lib/shale/utils.rb
CHANGED
@@ -5,6 +5,46 @@ module Shale
|
|
5
5
|
#
|
6
6
|
# @api private
|
7
7
|
module Utils
|
8
|
+
# Convert string to Ruby's class naming convention
|
9
|
+
#
|
10
|
+
# @param [String] val
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# Shale::Utils.classify('foobar')
|
14
|
+
# # => 'Foobar'
|
15
|
+
#
|
16
|
+
# @api private
|
17
|
+
def self.classify(str)
|
18
|
+
str = str.to_s.sub(/.*\./, '')
|
19
|
+
|
20
|
+
str = str.sub(/^[a-z\d]*/) { |match| match.capitalize || match }
|
21
|
+
|
22
|
+
str.gsub(%r{(?:_|-|(/))([a-z\d]*)}i) do
|
23
|
+
word = Regexp.last_match(2)
|
24
|
+
substituted = word.capitalize || word
|
25
|
+
Regexp.last_match(1) ? "::#{substituted}" : substituted
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Convert string to snake case
|
30
|
+
#
|
31
|
+
# @param [String] val
|
32
|
+
#
|
33
|
+
# @example
|
34
|
+
# Shale::Utils.snake_case('FooBar')
|
35
|
+
# # => 'foo_bar'
|
36
|
+
#
|
37
|
+
# @api private
|
38
|
+
def self.snake_case(str)
|
39
|
+
return str.to_s unless /[A-Z-]|::/.match?(str)
|
40
|
+
word = str.to_s.gsub('::', '/')
|
41
|
+
word = word.gsub(/([A-Z]+)(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) do
|
42
|
+
"#{Regexp.last_match(1) || Regexp.last_match(2)}_"
|
43
|
+
end
|
44
|
+
word = word.tr('-', '_')
|
45
|
+
word.downcase
|
46
|
+
end
|
47
|
+
|
8
48
|
# Convert word to under score
|
9
49
|
#
|
10
50
|
# @param [String] word
|
@@ -14,13 +54,8 @@ module Shale
|
|
14
54
|
# Shale::Utils.underscore('Namespace::FooBar') # => foo_bar
|
15
55
|
#
|
16
56
|
# @api private
|
17
|
-
def self.underscore(
|
18
|
-
|
19
|
-
.split('::')
|
20
|
-
.last
|
21
|
-
.gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
22
|
-
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
23
|
-
.downcase
|
57
|
+
def self.underscore(str)
|
58
|
+
snake_case(str).split('/').last
|
24
59
|
end
|
25
60
|
|
26
61
|
# Return value or nil if value is empty
|
data/lib/shale/version.rb
CHANGED
data/lib/shale.rb
CHANGED
@@ -4,7 +4,6 @@ require 'yaml'
|
|
4
4
|
|
5
5
|
require_relative 'shale/mapper'
|
6
6
|
require_relative 'shale/adapter/json'
|
7
|
-
require_relative 'shale/adapter/rexml'
|
8
7
|
require_relative 'shale/type/boolean'
|
9
8
|
require_relative 'shale/type/date'
|
10
9
|
require_relative 'shale/type/float'
|
@@ -73,15 +72,34 @@ module Shale
|
|
73
72
|
# @api public
|
74
73
|
attr_writer :yaml_adapter
|
75
74
|
|
76
|
-
#
|
75
|
+
# TOML adapter accessor.
|
76
|
+
#
|
77
|
+
# @param [@see Shale::Adapter::TomlRB] adapter
|
78
|
+
#
|
79
|
+
# @example setting adapter
|
80
|
+
# Shale.toml_adapter = Shale::Adapter::TomlRB
|
81
|
+
#
|
82
|
+
# @example getting adapter
|
83
|
+
# Shale.toml_adapter
|
84
|
+
# # => Shale::Adapter::TomlRB
|
85
|
+
#
|
86
|
+
# @api public
|
87
|
+
attr_accessor :toml_adapter
|
88
|
+
|
89
|
+
# XML adapter accessor. Available adapters are Shale::Adapter::REXML,
|
90
|
+
# Shale::Adapter::Nokogiri and Shale::Adapter::Ox
|
77
91
|
#
|
78
92
|
# @param [@see Shale::Adapter::REXML] adapter
|
79
93
|
#
|
80
|
-
# @example
|
94
|
+
# @example setting adapter
|
81
95
|
# Shale.xml_adapter = Shale::Adapter::REXML
|
82
96
|
#
|
97
|
+
# @example getting adapter
|
98
|
+
# Shale.xml_adapter
|
99
|
+
# # => Shale::Adapter::REXML
|
100
|
+
#
|
83
101
|
# @api public
|
84
|
-
|
102
|
+
attr_accessor :xml_adapter
|
85
103
|
|
86
104
|
# Return JSON adapter. By default Shale::Adapter::JSON is used
|
87
105
|
#
|
@@ -108,20 +126,5 @@ module Shale
|
|
108
126
|
def yaml_adapter
|
109
127
|
@yaml_adapter || YAML
|
110
128
|
end
|
111
|
-
|
112
|
-
# Return XML adapter. By default Shale::Adapter::REXML is used.
|
113
|
-
# Available adapters are Shale::Adapter::REXML,
|
114
|
-
# Shale::Adapter::Nokogiri and Shale::Adapter::Ox
|
115
|
-
#
|
116
|
-
# @return [@see Shale::Adapter::REXML]
|
117
|
-
#
|
118
|
-
# @example
|
119
|
-
# Shale.xml_adapter
|
120
|
-
# # => Shale::Adapter::REXML
|
121
|
-
#
|
122
|
-
# @api public
|
123
|
-
def xml_adapter
|
124
|
-
@xml_adapter || Adapter::REXML
|
125
|
-
end
|
126
129
|
end
|
127
130
|
end
|
data/shale.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ['Kamil Giszczak']
|
9
9
|
spec.email = ['beerkg@gmail.com']
|
10
10
|
|
11
|
-
spec.summary = 'Ruby object mapper and serializer for XML, JSON and YAML.'
|
12
|
-
spec.description = 'Ruby object mapper and serializer for XML, JSON and YAML.'
|
11
|
+
spec.summary = 'Ruby object mapper and serializer for XML, JSON, TOML and YAML.'
|
12
|
+
spec.description = 'Ruby object mapper and serializer for XML, JSON, TOML and YAML.'
|
13
13
|
spec.homepage = 'https://shalerb.org'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -26,5 +26,5 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.bindir = 'exe'
|
27
27
|
spec.executables = 'shaleb'
|
28
28
|
|
29
|
-
spec.required_ruby_version = '>= 2.
|
29
|
+
spec.required_ruby_version = '>= 2.7.0'
|
30
30
|
end
|