shale 0.3.0 → 0.5.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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -0
  3. data/README.md +200 -21
  4. data/exe/shaleb +108 -36
  5. data/lib/shale/adapter/nokogiri/document.rb +87 -0
  6. data/lib/shale/adapter/nokogiri/node.rb +100 -0
  7. data/lib/shale/adapter/nokogiri.rb +11 -151
  8. data/lib/shale/adapter/ox/document.rb +80 -0
  9. data/lib/shale/adapter/ox/node.rb +88 -0
  10. data/lib/shale/adapter/ox.rb +9 -134
  11. data/lib/shale/adapter/rexml/document.rb +88 -0
  12. data/lib/shale/adapter/rexml/node.rb +99 -0
  13. data/lib/shale/adapter/rexml.rb +9 -150
  14. data/lib/shale/attribute.rb +6 -0
  15. data/lib/shale/error.rb +39 -0
  16. data/lib/shale/mapper.rb +8 -6
  17. data/lib/shale/schema/compiler/boolean.rb +21 -0
  18. data/lib/shale/schema/compiler/complex.rb +88 -0
  19. data/lib/shale/schema/compiler/date.rb +21 -0
  20. data/lib/shale/schema/compiler/float.rb +21 -0
  21. data/lib/shale/schema/compiler/integer.rb +21 -0
  22. data/lib/shale/schema/compiler/property.rb +70 -0
  23. data/lib/shale/schema/compiler/string.rb +21 -0
  24. data/lib/shale/schema/compiler/time.rb +21 -0
  25. data/lib/shale/schema/compiler/value.rb +21 -0
  26. data/lib/shale/schema/compiler/xml_complex.rb +50 -0
  27. data/lib/shale/schema/compiler/xml_property.rb +73 -0
  28. data/lib/shale/schema/json_compiler.rb +331 -0
  29. data/lib/shale/schema/{json → json_generator}/base.rb +2 -2
  30. data/lib/shale/schema/{json → json_generator}/boolean.rb +1 -1
  31. data/lib/shale/schema/{json → json_generator}/collection.rb +2 -2
  32. data/lib/shale/schema/{json → json_generator}/date.rb +1 -1
  33. data/lib/shale/schema/{json → json_generator}/float.rb +1 -1
  34. data/lib/shale/schema/{json → json_generator}/integer.rb +1 -1
  35. data/lib/shale/schema/{json → json_generator}/object.rb +5 -2
  36. data/lib/shale/schema/{json → json_generator}/ref.rb +1 -1
  37. data/lib/shale/schema/{json → json_generator}/schema.rb +7 -5
  38. data/lib/shale/schema/{json → json_generator}/string.rb +1 -1
  39. data/lib/shale/schema/{json → json_generator}/time.rb +1 -1
  40. data/lib/shale/schema/json_generator/value.rb +23 -0
  41. data/lib/shale/schema/{json.rb → json_generator.rb} +36 -36
  42. data/lib/shale/schema/xml_compiler.rb +919 -0
  43. data/lib/shale/schema/{xml → xml_generator}/attribute.rb +1 -1
  44. data/lib/shale/schema/{xml → xml_generator}/complex_type.rb +5 -2
  45. data/lib/shale/schema/{xml → xml_generator}/element.rb +1 -1
  46. data/lib/shale/schema/{xml → xml_generator}/import.rb +1 -1
  47. data/lib/shale/schema/{xml → xml_generator}/ref_attribute.rb +1 -1
  48. data/lib/shale/schema/{xml → xml_generator}/ref_element.rb +1 -1
  49. data/lib/shale/schema/{xml → xml_generator}/schema.rb +5 -5
  50. data/lib/shale/schema/{xml → xml_generator}/typed_attribute.rb +1 -1
  51. data/lib/shale/schema/{xml → xml_generator}/typed_element.rb +1 -1
  52. data/lib/shale/schema/{xml.rb → xml_generator.rb} +25 -26
  53. data/lib/shale/schema.rb +44 -5
  54. data/lib/shale/type/{composite.rb → complex.rb} +34 -22
  55. data/lib/shale/utils.rb +42 -7
  56. data/lib/shale/version.rb +1 -1
  57. data/lib/shale.rb +8 -19
  58. data/shale.gemspec +1 -1
  59. metadata +47 -27
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Shale
4
4
  module Schema
5
- class XML
5
+ class XMLGenerator
6
6
  # Class representing XML Schema <attribute> element.
7
7
  # Serves as a base class for TypedAttribute and RefAttribute
8
8
  #
@@ -5,7 +5,7 @@ require_relative 'element'
5
5
 
6
6
  module Shale
7
7
  module Schema
8
- class XML
8
+ class XMLGenerator
9
9
  # Class representing XML Schema <complexType> element
10
10
  #
11
11
  # @api private
@@ -20,7 +20,10 @@ module Shale
20
20
  # Initialize ComplexType object
21
21
  #
22
22
  # @param [String] name
23
- # @param [Array<Shale::Schema::XML::Element, Shale::Schema::XML::Attribute>] children
23
+ # @param [Array<
24
+ # Shale::Schema::XMLGenerator::Element,
25
+ # Shale::Schema::XMLGenerator::Attribute
26
+ # >] children
24
27
  # @param [true, false] mixed
25
28
  #
26
29
  # @api private
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Shale
4
4
  module Schema
5
- class XML
5
+ class XMLGenerator
6
6
  # Class representing XML Schema <element> element.
7
7
  # Serves as a base class for TypedElement and RefElement
8
8
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Shale
4
4
  module Schema
5
- class XML
5
+ class XMLGenerator
6
6
  # Class representing XML Schema <import> element
7
7
  #
8
8
  # @api private
@@ -4,7 +4,7 @@ require_relative 'attribute'
4
4
 
5
5
  module Shale
6
6
  module Schema
7
- class XML
7
+ class XMLGenerator
8
8
  # Class representing XML Schema <attribute ref=""> element
9
9
  # with a reference
10
10
  #
@@ -4,7 +4,7 @@ require_relative 'element'
4
4
 
5
5
  module Shale
6
6
  module Schema
7
- class XML
7
+ class XMLGenerator
8
8
  # Class representing XML Schema <element ref=""> element
9
9
  # with a reference
10
10
  #
@@ -5,7 +5,7 @@ require_relative 'complex_type'
5
5
 
6
6
  module Shale
7
7
  module Schema
8
- class XML
8
+ class XMLGenerator
9
9
  class Schema
10
10
  # XML Schema namespace
11
11
  # @api private
@@ -43,10 +43,10 @@ module Shale
43
43
 
44
44
  # Add child element to XML Schema
45
45
  #
46
- # @param [Shale::Schema::XML::Import,
47
- # Shale::Schema::XML::Element,
48
- # Shale::Schema::XML::Attribute,
49
- # Shale::Schema::XML::ComplesType] child
46
+ # @param [Shale::Schema::XMLGenerator::Import,
47
+ # Shale::Schema::XMLGenerator::Element,
48
+ # Shale::Schema::XMLGenerator::Attribute,
49
+ # Shale::Schema::XMLGenerator::ComplesType] child
50
50
  #
51
51
  # @api private
52
52
  def add_child(child)
@@ -4,7 +4,7 @@ require_relative 'attribute'
4
4
 
5
5
  module Shale
6
6
  module Schema
7
- class XML
7
+ class XMLGenerator
8
8
  # Class representing XML Schema <attribute name="" type=""> element
9
9
  # with a name and a type
10
10
  #
@@ -4,7 +4,7 @@ require_relative 'element'
4
4
 
5
5
  module Shale
6
6
  module Schema
7
- class XML
7
+ class XMLGenerator
8
8
  # Class representing XML Schema <element mame="" type=""> element
9
9
  # with a name and a type
10
10
  #
@@ -1,20 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../../shale'
4
- require_relative 'xml/complex_type'
5
- require_relative 'xml/import'
6
- require_relative 'xml/ref_attribute'
7
- require_relative 'xml/ref_element'
8
- require_relative 'xml/schema'
9
- require_relative 'xml/typed_attribute'
10
- require_relative 'xml/typed_element'
4
+ require_relative 'xml_generator/complex_type'
5
+ require_relative 'xml_generator/import'
6
+ require_relative 'xml_generator/ref_attribute'
7
+ require_relative 'xml_generator/ref_element'
8
+ require_relative 'xml_generator/schema'
9
+ require_relative 'xml_generator/typed_attribute'
10
+ require_relative 'xml_generator/typed_element'
11
11
 
12
12
  module Shale
13
13
  module Schema
14
- # Class for handling XML schema
14
+ # Class for generating XML schema
15
15
  #
16
16
  # @api public
17
- class XML
17
+ class XMLGenerator
18
18
  # XML Schema default name
19
19
  # @api private
20
20
  DEFAULT_SCHEMA_NAME = 'schema'
@@ -27,7 +27,7 @@ module Shale
27
27
  # @param [String] xml_type
28
28
  #
29
29
  # @example
30
- # Shale::Schema::XML.register_xml_type(Shale::Type::String, 'myType')
30
+ # Shale::Schema::XMLGenerator.register_xml_type(Shale::Type::String, 'myType')
31
31
  #
32
32
  # @api public
33
33
  def self.register_xml_type(shale_type, xml_type)
@@ -41,7 +41,7 @@ module Shale
41
41
  # @return [String]
42
42
  #
43
43
  # @example
44
- # Shale::Schema::XML.get_xml_type(Shale::Type::String)
44
+ # Shale::Schema::XMLGenerator.get_xml_type(Shale::Type::String)
45
45
  # # => 'string'
46
46
  #
47
47
  # @api private
@@ -54,19 +54,20 @@ module Shale
54
54
  register_xml_type(Shale::Type::Float, 'decimal')
55
55
  register_xml_type(Shale::Type::Integer, 'integer')
56
56
  register_xml_type(Shale::Type::Time, 'dateTime')
57
+ register_xml_type(Shale::Type::Value, 'anyType')
57
58
 
58
59
  # Generate XML Schema from Shale model and return
59
- # it as a Shale::Schema::XML::Schema array
60
+ # it as a Shale::Schema::XMLGenerator::Schema array
60
61
  #
61
62
  # @param [Shale::Mapper] klass
62
63
  # @param [String, nil] base_name
63
64
  #
64
65
  # @raise [NotAShaleMapperError] when attribute is not a Shale model
65
66
  #
66
- # @return [Array<Shale::Schema::XML::Schema>]
67
+ # @return [Array<Shale::Schema::XMLGenerator::Schema>]
67
68
  #
68
69
  # @example
69
- # Shale::Schema::XML.new.as_schemas(Person)
70
+ # Shale::Schema::XMLGenerator.new.as_schemas(Person)
70
71
  #
71
72
  # @api public
72
73
  def as_schemas(klass, base_name = nil)
@@ -93,11 +94,12 @@ module Shale
93
94
  )
94
95
  schemas[default_namespace.name].add_child(root_element)
95
96
 
96
- composites = collect_composite_types(klass, klass.xml_mapping.default_namespace.name)
97
+ complexes = []
98
+ collect_complex_types(complexes, klass, klass.xml_mapping.default_namespace.name)
97
99
 
98
- composites.each do |composite|
99
- type = composite[:type]
100
- namespace = composite[:namespace]
100
+ complexes.each do |complex|
101
+ type = complex[:type]
102
+ namespace = complex[:namespace]
101
103
  children = []
102
104
 
103
105
  type.xml_mapping.elements.values.each do |mapping|
@@ -214,7 +216,7 @@ module Shale
214
216
  # @return [Hash<String, String>]
215
217
  #
216
218
  # @example
217
- # Shale::Schema::XML.new.to_schemas(Person)
219
+ # Shale::Schema::XMLGenerator.new.to_schemas(Person)
218
220
  #
219
221
  # @api public
220
222
  def to_schemas(klass, base_name = nil, pretty: false, declaration: false)
@@ -245,14 +247,13 @@ module Shale
245
247
 
246
248
  # Collect recursively Shale::Mapper types
247
249
  #
250
+ # @param [Array<Shale::Mapper>] types
248
251
  # @param [Shale::Mapper] type
249
252
  # @param [String, nil] namespace
250
253
  #
251
- # @return [Array<Hash<Symbol, String>>]
252
- #
253
254
  # @api private
254
- def collect_composite_types(type, namespace)
255
- types = [{ type: type, namespace: namespace }]
255
+ def collect_complex_types(types, type, namespace)
256
+ types << { type: type, namespace: namespace }
256
257
 
257
258
  type.xml_mapping.elements.values.each do |mapping|
258
259
  attribute = type.attributes[mapping.attribute]
@@ -262,11 +263,9 @@ module Shale
262
263
  is_included = types.include?({ type: attribute.type, namespace: namespace })
263
264
 
264
265
  if is_mapper && !is_included
265
- types += collect_composite_types(attribute.type, mapping.namespace.name)
266
+ collect_complex_types(types, attribute.type, mapping.namespace.name)
266
267
  end
267
268
  end
268
-
269
- types.uniq
270
269
  end
271
270
 
272
271
  # Convert Ruby class name to XML Schema name
data/lib/shale/schema.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'schema/json'
4
- require_relative 'schema/xml'
3
+ require_relative 'schema/json_generator'
4
+ require_relative 'schema/json_compiler'
5
+ require_relative 'schema/xml_generator'
6
+ require_relative 'schema/xml_compiler'
5
7
 
6
8
  module Shale
7
9
  # Module for handling JSON and XML schema
@@ -22,8 +24,30 @@ module Shale
22
24
  # # => JSON schema
23
25
  #
24
26
  # @api public
25
- def self.to_json(klass, id: nil, description: nil, pretty: false)
26
- JSON.new.to_schema(klass, id: id, description: description, pretty: pretty)
27
+ def self.to_json(klass, id: nil, title: nil, description: nil, pretty: false)
28
+ JSONGenerator.new.to_schema(
29
+ klass,
30
+ id: id,
31
+ title: title,
32
+ description: description,
33
+ pretty: pretty
34
+ )
35
+ end
36
+
37
+ # Generate Shale model from JSON Schema
38
+ #
39
+ # @param [Array<String>] schemas
40
+ # @param [String, nil] root_name
41
+ #
42
+ # @return [Array<String>]
43
+ #
44
+ # @example
45
+ # Shale::Schema.from_json([json_schema1, json_schema2], root_name: 'foobar')
46
+ # # => [model1, model2, model3]
47
+ #
48
+ # @api public
49
+ def self.from_json(schemas, root_name: nil)
50
+ JSONCompiler.new.to_models(schemas, root_name: root_name)
27
51
  end
28
52
 
29
53
  # Generate XML Schema from Shale model
@@ -41,7 +65,22 @@ module Shale
41
65
  #
42
66
  # @api public
43
67
  def self.to_xml(klass, base_name = nil, pretty: false, declaration: false)
44
- XML.new.to_schemas(klass, base_name, pretty: pretty, declaration: declaration)
68
+ XMLGenerator.new.to_schemas(klass, base_name, pretty: pretty, declaration: declaration)
69
+ end
70
+
71
+ # Generate Shale model from XML Schema
72
+ #
73
+ # @param [Array<String>] schemas
74
+ #
75
+ # @return [Array<String>]
76
+ #
77
+ # @example
78
+ # Shale::Schema.from_xml([xml_schema1, xml_schema2])
79
+ # # => [model1, model2, model3]
80
+ #
81
+ # @api public
82
+ def self.from_xml(schemas)
83
+ XMLCompiler.new.to_models(schemas)
45
84
  end
46
85
  end
47
86
  end
@@ -1,14 +1,15 @@
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 composite object. Don't use it directly.
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 Composite < Value
12
+ class Complex < Value
12
13
  class << self
13
14
  %i[hash json yaml].each do |format|
14
15
  class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
@@ -35,18 +36,15 @@ module Shale
35
36
  next unless attribute
36
37
 
37
38
  if value.nil?
38
- instance.public_send("\#{attribute.name}=", nil)
39
- next
40
- end
41
-
42
- if attribute.collection?
39
+ instance.send(attribute.setter, nil)
40
+ elsif attribute.collection?
43
41
  [*value].each do |val|
44
42
  val = val ? attribute.type.of_#{format}(val) : val
45
- instance.public_send(attribute.name) << attribute.type.cast(val)
43
+ instance.send(attribute.name) << attribute.type.cast(val)
46
44
  end
47
45
  else
48
46
  val = attribute.type.of_#{format}(value)
49
- instance.public_send("\#{attribute.name}=", val)
47
+ instance.send(attribute.setter, val)
50
48
  end
51
49
  end
52
50
  end
@@ -71,14 +69,11 @@ module Shale
71
69
  attribute = instance.class.attributes[mapping.attribute]
72
70
  next unless attribute
73
71
 
74
- value = instance.public_send(attribute.name)
72
+ value = instance.send(attribute.name)
75
73
 
76
74
  if value.nil?
77
75
  hash[mapping.name] = nil
78
- next
79
- end
80
-
81
- if attribute.collection?
76
+ elsif attribute.collection?
82
77
  hash[mapping.name] = [*value].map do |v|
83
78
  v ? attribute.type.as_#{format}(v) : v
84
79
  end
@@ -163,9 +158,9 @@ module Shale
163
158
  next unless attribute
164
159
 
165
160
  if attribute.collection?
166
- instance.public_send(attribute.name) << attribute.type.cast(value)
161
+ instance.send(attribute.name) << attribute.type.cast(value)
167
162
  else
168
- instance.public_send("#{attribute.name}=", value)
163
+ instance.send(attribute.setter, value)
169
164
  end
170
165
  end
171
166
  end
@@ -174,7 +169,7 @@ module Shale
174
169
  attribute = attributes[xml_mapping.content]
175
170
 
176
171
  if attribute
177
- instance.public_send("#{attribute.name}=", attribute.type.of_xml(element))
172
+ instance.send(attribute.setter, attribute.type.of_xml(element))
178
173
  end
179
174
  end
180
175
 
@@ -190,9 +185,9 @@ module Shale
190
185
 
191
186
  if attribute.collection?
192
187
  value = attribute.type.of_xml(node)
193
- instance.public_send(attribute.name) << attribute.type.cast(value)
188
+ instance.send(attribute.name) << attribute.type.cast(value)
194
189
  else
195
- instance.public_send("#{attribute.name}=", attribute.type.of_xml(node))
190
+ instance.send(attribute.setter, attribute.type.of_xml(node))
196
191
  end
197
192
  end
198
193
  end
@@ -204,10 +199,13 @@ module Shale
204
199
  #
205
200
  # @param [String] xml XML to convert
206
201
  #
202
+ # @raise [AdapterError]
203
+ #
207
204
  # @return [Shale::Mapper]
208
205
  #
209
206
  # @api public
210
207
  def from_xml(xml)
208
+ validate_xml_adapter
211
209
  of_xml(Shale.xml_adapter.load(xml))
212
210
  end
213
211
 
@@ -237,7 +235,7 @@ module Shale
237
235
  attribute = instance.class.attributes[mapping.attribute]
238
236
  next unless attribute
239
237
 
240
- value = instance.public_send(attribute.name)
238
+ value = instance.send(attribute.name)
241
239
  next if value.nil?
242
240
 
243
241
  doc.add_namespace(mapping.namespace.prefix, mapping.namespace.name)
@@ -249,7 +247,7 @@ module Shale
249
247
  attribute = instance.class.attributes[xml_mapping.content]
250
248
 
251
249
  if attribute
252
- value = instance.public_send(attribute.name)
250
+ value = instance.send(attribute.name)
253
251
  doc.add_text(element, value.to_s) if value
254
252
  end
255
253
  end
@@ -261,7 +259,7 @@ module Shale
261
259
  attribute = instance.class.attributes[mapping.attribute]
262
260
  next unless attribute
263
261
 
264
- value = instance.public_send(attribute.name)
262
+ value = instance.send(attribute.name)
265
263
  next if value.nil?
266
264
 
267
265
  doc.add_namespace(mapping.namespace.prefix, mapping.namespace.name)
@@ -285,12 +283,26 @@ module Shale
285
283
  # @param [Shale::Mapper] instance Object to convert
286
284
  # @param [Array<Symbol>] options
287
285
  #
286
+ # @raise [AdapterError]
287
+ #
288
288
  # @return [String]
289
289
  #
290
290
  # @api public
291
291
  def to_xml(instance, *options)
292
+ validate_xml_adapter
292
293
  Shale.xml_adapter.dump(as_xml(instance), *options)
293
294
  end
295
+
296
+ private
297
+
298
+ # Validate XML adapter
299
+ #
300
+ # @raise [AdapterError]
301
+ #
302
+ # @api private
303
+ def validate_xml_adapter
304
+ raise AdapterError, ADAPTER_NOT_SET_MESSAGE unless Shale.xml_adapter
305
+ end
294
306
  end
295
307
 
296
308
  # Convert Object to Hash
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(word)
18
- word
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Shale
4
4
  # @api private
5
- VERSION = '0.3.0'
5
+ VERSION = '0.5.0'
6
6
  end
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,20 @@ module Shale
73
72
  # @api public
74
73
  attr_writer :yaml_adapter
75
74
 
76
- # Set XML adapter
75
+ # XML adapter accessor. Available adapters are Shale::Adapter::REXML,
76
+ # Shale::Adapter::Nokogiri and Shale::Adapter::Ox
77
77
  #
78
78
  # @param [@see Shale::Adapter::REXML] adapter
79
79
  #
80
- # @example
80
+ # @example setting adapter
81
81
  # Shale.xml_adapter = Shale::Adapter::REXML
82
82
  #
83
+ # @example getting adapter
84
+ # Shale.xml_adapter
85
+ # # => Shale::Adapter::REXML
86
+ #
83
87
  # @api public
84
- attr_writer :xml_adapter
88
+ attr_accessor :xml_adapter
85
89
 
86
90
  # Return JSON adapter. By default Shale::Adapter::JSON is used
87
91
  #
@@ -108,20 +112,5 @@ module Shale
108
112
  def yaml_adapter
109
113
  @yaml_adapter || YAML
110
114
  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
115
  end
127
116
  end
data/shale.gemspec CHANGED
@@ -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.6.0'
29
+ spec.required_ruby_version = '>= 2.7.0'
30
30
  end