xml2json-rb 0.3.1 → 0.3.2
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 +4 -4
- data/Cargo.lock +1 -1
- data/ext/xml2json/Cargo.toml +1 -1
- data/ext/xml2json/src/lib.rs +38 -25
- data/lib/xml2json/version.rb +1 -1
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef6f85b883fb1df89aa98b03908137ce38568434f4ac1c84456da42be613e636
|
4
|
+
data.tar.gz: c519a3d628e6e07356bd0892eeed6e13e3775423c21350d46e4cf59464eb50d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e7c60d98d3d92e3570c928cd05c257845aea1073ded6dcdeff7fd731808d9f38b17f0919cbb2fa9ef4679c7ce233b7ef9c0fa5ff12d761b0286c65525bd8bd8
|
7
|
+
data.tar.gz: d5da3cd90ca19975c7d933b14ffe6ac442faf6069916cf79accdf2ed90508aa04126d749494789c30fcc2b7c991f71422d48001a8248102da5cce0207f54ca4c
|
data/Cargo.lock
CHANGED
data/ext/xml2json/Cargo.toml
CHANGED
data/ext/xml2json/src/lib.rs
CHANGED
@@ -1,15 +1,26 @@
|
|
1
|
-
use magnus::{define_module, function, prelude::*, Error, Value};
|
2
|
-
use magnus::scan_args::{scan_args};
|
1
|
+
use magnus::{define_module, scan_args::scan_args, function, prelude::*, Error, TryConvert, Value};
|
3
2
|
use xml2json_rs::{XmlBuilder, JsonBuilder, JsonConfig, XmlConfig, Declaration, Version, Encoding, Indentation};
|
4
3
|
|
5
4
|
#[macro_export]
|
6
5
|
macro_rules! set_arg {
|
7
|
-
($config:expr, $opts_hash:expr, $arg:ident, $arg_type:ident) =>
|
8
|
-
let arg_value = $opts_hash.
|
6
|
+
($config:expr, $opts_hash:expr, $arg:ident, $arg_type:ident) => {{
|
7
|
+
let arg_value: Option<Value> = $opts_hash.get(magnus::Symbol::new(stringify!($arg)));
|
9
8
|
if let Some(value) = arg_value {
|
10
|
-
$config.$arg(value);
|
9
|
+
$config.$arg(<$arg_type as TryConvert>::try_convert(value)?);
|
11
10
|
}
|
12
|
-
|
11
|
+
}};
|
12
|
+
}
|
13
|
+
|
14
|
+
#[macro_export]
|
15
|
+
macro_rules! get_arg {
|
16
|
+
($opts_hash:expr, $arg:ident, $arg_type:ident) => {{
|
17
|
+
let arg_value: Option<Value> = $opts_hash.get(magnus::Symbol::new(stringify!($arg)));
|
18
|
+
if let Some(value) = arg_value {
|
19
|
+
Some(<$arg_type as TryConvert>::try_convert(value)?)
|
20
|
+
} else {
|
21
|
+
None
|
22
|
+
}
|
23
|
+
}};
|
13
24
|
}
|
14
25
|
|
15
26
|
fn map_xml2json_err(error: xml2json_rs::X2JError) -> Error {
|
@@ -37,46 +48,49 @@ fn build_xml_impl(args: &[Value], build_pretty: bool) -> Result<String, Error> {
|
|
37
48
|
set_arg!(config, opts_hash, attrkey, String);
|
38
49
|
set_arg!(config, opts_hash, charkey, String);
|
39
50
|
|
40
|
-
let decl_version = opts_hash.
|
41
|
-
let decl_encoding = opts_hash.
|
42
|
-
let decl_standalone = opts_hash.
|
51
|
+
let decl_version = opts_hash.get(magnus::Symbol::new("version"));
|
52
|
+
let decl_encoding = opts_hash.get(magnus::Symbol::new("encoding"));
|
53
|
+
let decl_standalone = opts_hash.get(magnus::Symbol::new("standalone"));
|
43
54
|
if decl_version.is_some()
|
44
55
|
|| decl_encoding.is_some()
|
45
56
|
|| decl_standalone.is_some()
|
46
57
|
{ // something is specified
|
47
58
|
// I didn't find a way to get defaults without copying them
|
48
|
-
let decl_version_val = if
|
49
|
-
let decl_version_str = unsafe {
|
59
|
+
let decl_version_val = if let Some(decl_version_opt) = decl_version {
|
60
|
+
let decl_version_str = unsafe { decl_version_opt.to_s() }?.into_owned();
|
50
61
|
Version::try_from(decl_version_str.as_str())
|
51
62
|
.map_err(map_xml2json_err)?
|
52
63
|
} else { Version::XML10 };
|
53
|
-
let decl_encoding_val = if
|
54
|
-
let decl_encoding_str = unsafe {
|
64
|
+
let decl_encoding_val = if let Some(decl_encoding_opt) = decl_encoding {
|
65
|
+
let decl_encoding_str = unsafe { decl_encoding_opt.to_s() }?.into_owned();
|
55
66
|
Some(Encoding::try_from(decl_encoding_str.as_str())
|
56
67
|
.map_err(map_xml2json_err)?)
|
57
68
|
} else { None };
|
69
|
+
let decl_standalone_val = if let Some(decl_standalone_opt) = decl_standalone {
|
70
|
+
Some(TryConvert::try_convert(decl_standalone_opt)?)
|
71
|
+
} else { None };
|
58
72
|
|
59
73
|
let decl = Declaration::new(
|
60
74
|
decl_version_val,
|
61
75
|
decl_encoding_val,
|
62
|
-
|
76
|
+
decl_standalone_val,
|
63
77
|
);
|
64
78
|
config.decl(decl);
|
65
79
|
}
|
66
80
|
|
67
|
-
let indent = opts_hash
|
81
|
+
let indent = get_arg!(opts_hash, indent, bool);
|
68
82
|
if indent.unwrap_or(true) {
|
69
|
-
let
|
70
|
-
let
|
71
|
-
if
|
72
|
-
||
|
83
|
+
let indent_char_opt = get_arg!(opts_hash, indent_char, char);
|
84
|
+
let indent_size_opt = get_arg!(opts_hash, indent_size, usize);
|
85
|
+
if indent_char_opt.is_some()
|
86
|
+
|| indent_size_opt.is_some()
|
73
87
|
{
|
74
|
-
let indent_char_val: u8 = if indent_char
|
75
|
-
u8::try_from(indent_char
|
88
|
+
let indent_char_val: u8 = if let Some(indent_char) = indent_char_opt {
|
89
|
+
u8::try_from(indent_char).map_err(|error| Error::new(magnus::exception::type_error(), error.to_string()))?
|
76
90
|
} else { b' ' };
|
77
91
|
config.rendering(Indentation::new(
|
78
92
|
indent_char_val,
|
79
|
-
|
93
|
+
indent_size_opt.unwrap_or(2),
|
80
94
|
));
|
81
95
|
} else if indent.unwrap_or(build_pretty) {
|
82
96
|
// because Indentation::default is not the same as not calling config.rendering at all;
|
@@ -123,9 +137,8 @@ fn build_json_impl(args: &[Value], mut build_pretty: bool) -> Result<String, Err
|
|
123
137
|
set_arg!(config, opts_hash, explicit_charkey, bool);
|
124
138
|
json_builder = config.finalize();
|
125
139
|
|
126
|
-
let indent = opts_hash
|
127
|
-
|
128
|
-
build_pretty = indent_value;
|
140
|
+
if let Some(indent) = get_arg!(opts_hash, indent, bool) {
|
141
|
+
build_pretty = indent;
|
129
142
|
}
|
130
143
|
} else { json_builder = JsonBuilder::default(); }
|
131
144
|
|
data/lib/xml2json/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xml2json-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- uvlad7
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.21'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: base64
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: pry
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -205,9 +219,9 @@ metadata:
|
|
205
219
|
homepage_uri: https://github.com/uvlad7/xml2json-rb
|
206
220
|
source_code_uri: https://github.com/uvlad7/xml2json-rb
|
207
221
|
changelog_uri: https://github.com/uvlad7/xml2json-rb/blob/main/CHANGELOG.md
|
208
|
-
documentation_uri: https://rubydoc.info/gems/xml2json-rb/0.3.
|
222
|
+
documentation_uri: https://rubydoc.info/gems/xml2json-rb/0.3.2
|
209
223
|
rubygems_mfa_required: 'true'
|
210
|
-
post_install_message:
|
224
|
+
post_install_message:
|
211
225
|
rdoc_options: []
|
212
226
|
require_paths:
|
213
227
|
- lib
|
@@ -222,8 +236,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
236
|
- !ruby/object:Gem::Version
|
223
237
|
version: 3.3.11
|
224
238
|
requirements: []
|
225
|
-
rubygems_version: 3.4.
|
226
|
-
signing_key:
|
239
|
+
rubygems_version: 3.4.14
|
240
|
+
signing_key:
|
227
241
|
specification_version: 4
|
228
242
|
summary: Ruby wrapper for xml2json-rs
|
229
243
|
test_files: []
|