shale 0.4.0 → 0.7.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 +34 -0
- data/LICENSE.txt +1 -1
- data/README.md +449 -40
- data/exe/shaleb +30 -6
- data/lib/shale/adapter/json.rb +3 -3
- data/lib/shale/adapter/nokogiri/document.rb +97 -0
- data/lib/shale/adapter/nokogiri/node.rb +100 -0
- data/lib/shale/adapter/nokogiri.rb +17 -156
- data/lib/shale/adapter/ox/document.rb +90 -0
- data/lib/shale/adapter/ox/node.rb +97 -0
- data/lib/shale/adapter/ox.rb +14 -138
- data/lib/shale/adapter/rexml/document.rb +98 -0
- data/lib/shale/adapter/rexml/node.rb +99 -0
- data/lib/shale/adapter/rexml.rb +14 -154
- data/lib/shale/adapter/toml_rb.rb +34 -0
- data/lib/shale/error.rb +57 -2
- data/lib/shale/mapper.rb +61 -9
- data/lib/shale/mapping/descriptor/dict.rb +12 -1
- data/lib/shale/mapping/descriptor/xml.rb +12 -2
- data/lib/shale/mapping/dict.rb +26 -2
- data/lib/shale/mapping/xml.rb +52 -6
- data/lib/shale/schema/{json_compiler → compiler}/boolean.rb +1 -1
- data/lib/shale/schema/{json_compiler/object.rb → compiler/complex.rb} +11 -8
- data/lib/shale/schema/{json_compiler → compiler}/date.rb +1 -1
- data/lib/shale/schema/{json_compiler → compiler}/float.rb +1 -1
- data/lib/shale/schema/{json_compiler → compiler}/integer.rb +1 -1
- data/lib/shale/schema/{json_compiler → compiler}/property.rb +6 -6
- data/lib/shale/schema/{json_compiler → compiler}/string.rb +1 -1
- data/lib/shale/schema/{json_compiler → compiler}/time.rb +1 -1
- 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 +32 -34
- data/lib/shale/schema/json_generator.rb +4 -6
- data/lib/shale/schema/xml_compiler.rb +919 -0
- data/lib/shale/schema/xml_generator/import.rb +2 -2
- data/lib/shale/schema/xml_generator.rb +11 -13
- data/lib/shale/schema.rb +16 -0
- data/lib/shale/type/complex.rb +763 -0
- data/lib/shale/type/value.rb +38 -9
- 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 +26 -17
- data/lib/shale/schema/json_compiler/utils.rb +0 -52
- data/lib/shale/schema/json_compiler/value.rb +0 -13
- data/lib/shale/type/composite.rb +0 -331
data/lib/shale/type/value.rb
CHANGED
@@ -30,7 +30,7 @@ module Shale
|
|
30
30
|
# @return [any]
|
31
31
|
#
|
32
32
|
# @api private
|
33
|
-
def of_hash(value)
|
33
|
+
def of_hash(value, **)
|
34
34
|
value
|
35
35
|
end
|
36
36
|
|
@@ -41,7 +41,7 @@ module Shale
|
|
41
41
|
# @return [any]
|
42
42
|
#
|
43
43
|
# @api private
|
44
|
-
def as_hash(value)
|
44
|
+
def as_hash(value, **)
|
45
45
|
value
|
46
46
|
end
|
47
47
|
|
@@ -52,7 +52,7 @@ module Shale
|
|
52
52
|
# @return [any]
|
53
53
|
#
|
54
54
|
# @api private
|
55
|
-
def of_json(value)
|
55
|
+
def of_json(value, **)
|
56
56
|
value
|
57
57
|
end
|
58
58
|
|
@@ -63,7 +63,7 @@ module Shale
|
|
63
63
|
# @return [any]
|
64
64
|
#
|
65
65
|
# @api private
|
66
|
-
def as_json(value)
|
66
|
+
def as_json(value, **)
|
67
67
|
value
|
68
68
|
end
|
69
69
|
|
@@ -74,7 +74,7 @@ module Shale
|
|
74
74
|
# @return [any]
|
75
75
|
#
|
76
76
|
# @api private
|
77
|
-
def of_yaml(value)
|
77
|
+
def of_yaml(value, **)
|
78
78
|
value
|
79
79
|
end
|
80
80
|
|
@@ -85,7 +85,29 @@ module Shale
|
|
85
85
|
# @return [any]
|
86
86
|
#
|
87
87
|
# @api private
|
88
|
-
def as_yaml(value)
|
88
|
+
def as_yaml(value, **)
|
89
|
+
value
|
90
|
+
end
|
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, **)
|
89
111
|
value
|
90
112
|
end
|
91
113
|
|
@@ -96,7 +118,7 @@ module Shale
|
|
96
118
|
# @return [String]
|
97
119
|
#
|
98
120
|
# @api private
|
99
|
-
def of_xml(node)
|
121
|
+
def of_xml(node, **)
|
100
122
|
node.text
|
101
123
|
end
|
102
124
|
|
@@ -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
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kamil Giszczak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Ruby object mapper and serializer for XML, JSON and YAML.
|
13
|
+
description: Ruby object mapper and serializer for XML, JSON, TOML and YAML.
|
14
14
|
email:
|
15
15
|
- beerkg@gmail.com
|
16
16
|
executables:
|
@@ -25,8 +25,15 @@ files:
|
|
25
25
|
- lib/shale.rb
|
26
26
|
- lib/shale/adapter/json.rb
|
27
27
|
- lib/shale/adapter/nokogiri.rb
|
28
|
+
- lib/shale/adapter/nokogiri/document.rb
|
29
|
+
- lib/shale/adapter/nokogiri/node.rb
|
28
30
|
- lib/shale/adapter/ox.rb
|
31
|
+
- lib/shale/adapter/ox/document.rb
|
32
|
+
- lib/shale/adapter/ox/node.rb
|
29
33
|
- lib/shale/adapter/rexml.rb
|
34
|
+
- lib/shale/adapter/rexml/document.rb
|
35
|
+
- lib/shale/adapter/rexml/node.rb
|
36
|
+
- lib/shale/adapter/toml_rb.rb
|
30
37
|
- lib/shale/attribute.rb
|
31
38
|
- lib/shale/error.rb
|
32
39
|
- lib/shale/mapper.rb
|
@@ -37,17 +44,18 @@ files:
|
|
37
44
|
- lib/shale/mapping/validator.rb
|
38
45
|
- lib/shale/mapping/xml.rb
|
39
46
|
- lib/shale/schema.rb
|
47
|
+
- lib/shale/schema/compiler/boolean.rb
|
48
|
+
- lib/shale/schema/compiler/complex.rb
|
49
|
+
- lib/shale/schema/compiler/date.rb
|
50
|
+
- lib/shale/schema/compiler/float.rb
|
51
|
+
- lib/shale/schema/compiler/integer.rb
|
52
|
+
- lib/shale/schema/compiler/property.rb
|
53
|
+
- lib/shale/schema/compiler/string.rb
|
54
|
+
- lib/shale/schema/compiler/time.rb
|
55
|
+
- lib/shale/schema/compiler/value.rb
|
56
|
+
- lib/shale/schema/compiler/xml_complex.rb
|
57
|
+
- lib/shale/schema/compiler/xml_property.rb
|
40
58
|
- lib/shale/schema/json_compiler.rb
|
41
|
-
- lib/shale/schema/json_compiler/boolean.rb
|
42
|
-
- lib/shale/schema/json_compiler/date.rb
|
43
|
-
- lib/shale/schema/json_compiler/float.rb
|
44
|
-
- lib/shale/schema/json_compiler/integer.rb
|
45
|
-
- lib/shale/schema/json_compiler/object.rb
|
46
|
-
- lib/shale/schema/json_compiler/property.rb
|
47
|
-
- lib/shale/schema/json_compiler/string.rb
|
48
|
-
- lib/shale/schema/json_compiler/time.rb
|
49
|
-
- lib/shale/schema/json_compiler/utils.rb
|
50
|
-
- lib/shale/schema/json_compiler/value.rb
|
51
59
|
- lib/shale/schema/json_generator.rb
|
52
60
|
- lib/shale/schema/json_generator/base.rb
|
53
61
|
- lib/shale/schema/json_generator/boolean.rb
|
@@ -61,6 +69,7 @@ files:
|
|
61
69
|
- lib/shale/schema/json_generator/string.rb
|
62
70
|
- lib/shale/schema/json_generator/time.rb
|
63
71
|
- lib/shale/schema/json_generator/value.rb
|
72
|
+
- lib/shale/schema/xml_compiler.rb
|
64
73
|
- lib/shale/schema/xml_generator.rb
|
65
74
|
- lib/shale/schema/xml_generator/attribute.rb
|
66
75
|
- lib/shale/schema/xml_generator/complex_type.rb
|
@@ -72,7 +81,7 @@ files:
|
|
72
81
|
- lib/shale/schema/xml_generator/typed_attribute.rb
|
73
82
|
- lib/shale/schema/xml_generator/typed_element.rb
|
74
83
|
- lib/shale/type/boolean.rb
|
75
|
-
- lib/shale/type/
|
84
|
+
- lib/shale/type/complex.rb
|
76
85
|
- lib/shale/type/date.rb
|
77
86
|
- lib/shale/type/float.rb
|
78
87
|
- lib/shale/type/integer.rb
|
@@ -99,15 +108,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
108
|
requirements:
|
100
109
|
- - ">="
|
101
110
|
- !ruby/object:Gem::Version
|
102
|
-
version: 2.
|
111
|
+
version: 2.7.0
|
103
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
113
|
requirements:
|
105
114
|
- - ">="
|
106
115
|
- !ruby/object:Gem::Version
|
107
116
|
version: '0'
|
108
117
|
requirements: []
|
109
|
-
rubygems_version: 3.
|
118
|
+
rubygems_version: 3.3.7
|
110
119
|
signing_key:
|
111
120
|
specification_version: 4
|
112
|
-
summary: Ruby object mapper and serializer for XML, JSON and YAML.
|
121
|
+
summary: Ruby object mapper and serializer for XML, JSON, TOML and YAML.
|
113
122
|
test_files: []
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Shale
|
4
|
-
module Schema
|
5
|
-
class JSONCompiler
|
6
|
-
# Module with utility functions
|
7
|
-
#
|
8
|
-
# @api private
|
9
|
-
module Utils
|
10
|
-
# Convert string to Ruby's class naming convention
|
11
|
-
#
|
12
|
-
# @param [String] val
|
13
|
-
#
|
14
|
-
# @example
|
15
|
-
# Shale::Schema::JSONCompiler.classify('foobar')
|
16
|
-
# # => 'Foobar'
|
17
|
-
#
|
18
|
-
# @api private
|
19
|
-
def self.classify(str)
|
20
|
-
str = str.to_s.sub(/.*\./, '')
|
21
|
-
|
22
|
-
str = str.sub(/^[a-z\d]*/) { |match| match.capitalize || match }
|
23
|
-
|
24
|
-
str.gsub(%r{(?:_|(/))([a-z\d]*)}i) do
|
25
|
-
word = Regexp.last_match(2)
|
26
|
-
substituted = word.capitalize || word
|
27
|
-
Regexp.last_match(1) ? "::#{substituted}" : substituted
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# Convert string to snake case
|
32
|
-
#
|
33
|
-
# @param [String] val
|
34
|
-
#
|
35
|
-
# @example
|
36
|
-
# Shale::Schema::JSONCompiler.snake_case('FooBar')
|
37
|
-
# # => 'foo_bar'
|
38
|
-
#
|
39
|
-
# @api private
|
40
|
-
def self.snake_case(str)
|
41
|
-
return str.to_s unless /[A-Z-]|::/.match?(str)
|
42
|
-
word = str.to_s.gsub('::', '/')
|
43
|
-
word = word.gsub(/([A-Z]+)(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) do
|
44
|
-
"#{Regexp.last_match(1) || Regexp.last_match(2)}_"
|
45
|
-
end
|
46
|
-
word = word.tr('-', '_')
|
47
|
-
word.downcase
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|