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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 929c9024b54d50ca7dc4d457c75cd69ddb02d0f4394d25eb2d3b6c5e8573fd25
4
- data.tar.gz: 6e80dac62fb5f67fa6f19641cd0c0a62c91110d190a4ec38e6a461d166d3074b
3
+ metadata.gz: ef6f85b883fb1df89aa98b03908137ce38568434f4ac1c84456da42be613e636
4
+ data.tar.gz: c519a3d628e6e07356bd0892eeed6e13e3775423c21350d46e4cf59464eb50d9
5
5
  SHA512:
6
- metadata.gz: dcd614a2cbfd953cc2ae8adcf123a1723a0143f2754ca0ff3e42509cb385b283794d8090bd5808ed117c8e0e6f65bc630791052941848e2f46cb626e26599593
7
- data.tar.gz: 28e43cbfaaa8987a1f7fbb1ef348055e742886dc3b629874c0f04d67bd74789751dc1e288d93358ee4c8e0b0fe7a2a6fa0c88393cc426dfe7731c0056e146383
6
+ metadata.gz: 5e7c60d98d3d92e3570c928cd05c257845aea1073ded6dcdeff7fd731808d9f38b17f0919cbb2fa9ef4679c7ce233b7ef9c0fa5ff12d761b0286c65525bd8bd8
7
+ data.tar.gz: d5da3cd90ca19975c7d933b14ffe6ac442faf6069916cf79accdf2ed90508aa04126d749494789c30fcc2b7c991f71422d48001a8248102da5cce0207f54ca4c
data/Cargo.lock CHANGED
@@ -355,7 +355,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
355
355
 
356
356
  [[package]]
357
357
  name = "xml2json"
358
- version = "0.3.1"
358
+ version = "0.3.2"
359
359
  dependencies = [
360
360
  "magnus",
361
361
  "rb-sys",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "xml2json"
3
- version = "0.3.1"
3
+ version = "0.3.2"
4
4
  edition = "2021"
5
5
  authors = ["uvlad7 <uvlad7@gmail.com>"]
6
6
  license = "MIT"
@@ -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.lookup::<_, Option<$arg_type>>(magnus::Symbol::new(stringify!($arg)))?;
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.lookup::<_, Option<Value>>(magnus::Symbol::new("version"))?;
41
- let decl_encoding = opts_hash.lookup::<_, Option<Value>>(magnus::Symbol::new("encoding"))?;
42
- let decl_standalone = opts_hash.lookup::<_, Option<bool>>(magnus::Symbol::new("standalone"))?;
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 decl_version.is_some() {
49
- let decl_version_str = unsafe { decl_version.unwrap().to_s() }?.into_owned();
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 decl_encoding.is_some() {
54
- let decl_encoding_str = unsafe { decl_encoding.unwrap().to_s() }?.into_owned();
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
- decl_standalone,
76
+ decl_standalone_val,
63
77
  );
64
78
  config.decl(decl);
65
79
  }
66
80
 
67
- let indent = opts_hash.lookup::<_, Option<bool>>(magnus::Symbol::new("indent"))?;
81
+ let indent = get_arg!(opts_hash, indent, bool);
68
82
  if indent.unwrap_or(true) {
69
- let indent_char = opts_hash.lookup::<_, Option<char>>(magnus::Symbol::new("indent_char"))?;
70
- let indent_size = opts_hash.lookup::<_, Option<usize>>(magnus::Symbol::new("indent_size"))?;
71
- if indent_char.is_some()
72
- || indent_size.is_some()
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.is_some() {
75
- u8::try_from(indent_char.unwrap()).map_err(|error| Error::new(magnus::exception::type_error(), error.to_string()))?
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
- indent_size.unwrap_or(2),
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.lookup::<_, Option<bool>>(magnus::Symbol::new("indent"))?;
127
- if let Some(indent_value) = indent {
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Xml2Json
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
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.1
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: 2023-10-30 00:00:00.000000000 Z
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.1
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.20
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: []