chef-gyoku 1.4.1 → 1.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.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +12 -0
- data/.github/workflows/ci.yml +3 -5
- data/.github/workflows/lint.yml +27 -0
- data/.rubocop.yml +12 -0
- data/Rakefile +23 -1
- data/{gyoku.gemspec → chef-gyoku.gemspec} +6 -4
- data/lib/{gyoku → chef-gyoku}/array.rb +8 -8
- data/lib/{gyoku → chef-gyoku}/hash.rb +4 -4
- data/lib/{gyoku → chef-gyoku}/prettifier.rb +1 -1
- data/lib/chef-gyoku/version.rb +3 -0
- data/lib/{gyoku → chef-gyoku}/xml_key.rb +13 -13
- data/lib/{gyoku → chef-gyoku}/xml_value.rb +4 -4
- data/lib/{gyoku.rb → chef-gyoku.rb} +2 -2
- data/spec/{gyoku → chef-gyoku}/array_spec.rb +17 -17
- data/spec/{gyoku → chef-gyoku}/hash_spec.rb +78 -78
- data/spec/{gyoku → chef-gyoku}/prettifier_spec.rb +4 -4
- data/spec/{gyoku → chef-gyoku}/xml_key_spec.rb +8 -8
- data/spec/{gyoku → chef-gyoku}/xml_value_spec.rb +1 -1
- data/spec/{gyoku_spec.rb → chef-gyoku_spec.rb} +11 -11
- data/spec/spec_helper.rb +1 -1
- metadata +51 -20
- data/lib/gyoku/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cda5eed97e4ffe761f4cbda700252dc6c2b5a93d26ab885e67b1dc75ccabed03
|
4
|
+
data.tar.gz: fecbfabb394e73ce3c57893ea727565e368079d1a28ca5ba931ed0d2a0bdb850
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 609d24522f498586d62a31972d2c0045228716d43e26732d1e77708f37b5e9cf4b8970f8b53c0e2e292ddd650dc9067296d51d73c4b33e4fd46b3b5706a5d228
|
7
|
+
data.tar.gz: da04226ad912b1670fcf558acc2cb661658f41a85f4d387b84f63ad3b4b469275a99934a15edf1f3bbb1cfdd07ed352d394030d979b543d6a1d7397064915e02
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
3
|
+
# Please see the documentation for more information:
|
4
|
+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
5
|
+
# https://containers.dev/guide/dependabot
|
6
|
+
|
7
|
+
version: 2
|
8
|
+
updates:
|
9
|
+
- package-ecosystem: "devcontainers"
|
10
|
+
directory: "/"
|
11
|
+
schedule:
|
12
|
+
interval: weekly
|
data/.github/workflows/ci.yml
CHANGED
@@ -16,10 +16,8 @@ jobs:
|
|
16
16
|
fail-fast: true
|
17
17
|
matrix:
|
18
18
|
ruby:
|
19
|
-
- '3.
|
19
|
+
- '3.4'
|
20
20
|
- '3.1'
|
21
|
-
- '3.0'
|
22
|
-
- 'jruby'
|
23
21
|
|
24
22
|
runs-on: ubuntu-latest
|
25
23
|
|
@@ -47,7 +45,7 @@ jobs:
|
|
47
45
|
- name: Set up Ruby
|
48
46
|
uses: ruby/setup-ruby@v1
|
49
47
|
with:
|
50
|
-
ruby-version: 3.
|
48
|
+
ruby-version: 3.4
|
51
49
|
bundler-cache: true
|
52
50
|
|
53
51
|
- name: Install dependencies
|
@@ -59,4 +57,4 @@ jobs:
|
|
59
57
|
- name: Report coverage
|
60
58
|
uses: coverallsapp/github-action@v2
|
61
59
|
with:
|
62
|
-
flag-name: ruby-3.
|
60
|
+
flag-name: ruby-3.4
|
@@ -0,0 +1,27 @@
|
|
1
|
+
---
|
2
|
+
name: lint
|
3
|
+
|
4
|
+
on:
|
5
|
+
pull_request:
|
6
|
+
push:
|
7
|
+
branches:
|
8
|
+
- main
|
9
|
+
|
10
|
+
concurrency:
|
11
|
+
group: lint-${{ github.ref }}
|
12
|
+
cancel-in-progress: true
|
13
|
+
|
14
|
+
jobs:
|
15
|
+
lint:
|
16
|
+
runs-on: ubuntu-latest
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v4
|
19
|
+
- uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: 3.1
|
22
|
+
bundler-cache: false
|
23
|
+
- uses: r7kamura/rubocop-problem-matchers-action@v1 # this shows the failures in the PR
|
24
|
+
- run: |
|
25
|
+
gem install cookstyle
|
26
|
+
cookstyle --chefstyle -c .rubocop.yml
|
27
|
+
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.7
|
3
|
+
Exclude:
|
4
|
+
- "spec/data/**/*"
|
5
|
+
- "vendor/**/*"
|
6
|
+
- "pkg/**/*"
|
7
|
+
|
8
|
+
# these have shellout examples that need to have the tabs that come with the shellout
|
9
|
+
Layout/IndentationStyle:
|
10
|
+
Exclude:
|
11
|
+
- "lib/ohai/plugins/mono.rb"
|
12
|
+
- "lib/ohai/plugins/darwin/hardware.rb"
|
data/Rakefile
CHANGED
@@ -4,8 +4,30 @@ Bundler::GemHelper.install_tasks
|
|
4
4
|
|
5
5
|
require "rspec/core/rake_task"
|
6
6
|
|
7
|
+
desc "Check Linting and code style."
|
8
|
+
task :style do
|
9
|
+
require "rubocop/rake_task"
|
10
|
+
require "cookstyle/chefstyle"
|
11
|
+
|
12
|
+
if RbConfig::CONFIG["host_os"] =~ /mswin|mingw|windows/
|
13
|
+
# Windows-specific command, rubocop erroneously reports the CRLF in each file which is removed when your PR is uploaeded to GitHub.
|
14
|
+
# This is a workaround to ignore the CRLF from the files before running cookstyle.
|
15
|
+
sh "cookstyle --chefstyle -c .rubocop.yml --except Layout/EndOfLine"
|
16
|
+
else
|
17
|
+
sh "cookstyle --chefstyle -c .rubocop.yml"
|
18
|
+
end
|
19
|
+
rescue LoadError
|
20
|
+
puts "Rubocop or Cookstyle gems are not installed. bundle install first to make sure all dependencies are installed."
|
21
|
+
end
|
22
|
+
|
23
|
+
# Run the integration test suite
|
24
|
+
RSpec::Core::RakeTask.new(:integration) do |task|
|
25
|
+
task.pattern = "spec/chef-gyoku/*_spec.rb"
|
26
|
+
task.rspec_opts = ["--color", "-f documentation"]
|
27
|
+
end
|
28
|
+
|
7
29
|
RSpec::Core::RakeTask.new do |t|
|
8
|
-
t.rspec_opts = %w
|
30
|
+
t.rspec_opts = %w{-c}
|
9
31
|
end
|
10
32
|
|
11
33
|
task default: :spec
|
@@ -1,5 +1,5 @@
|
|
1
|
-
$:.push File.expand_path("
|
2
|
-
require "gyoku/version"
|
1
|
+
$:.push File.expand_path("lib", __dir__)
|
2
|
+
require "chef-gyoku/version"
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "chef-gyoku"
|
@@ -10,16 +10,18 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "https://github.com/savonrb/#{s.name}"
|
11
11
|
s.summary = "Translates Ruby Hashes to XML"
|
12
12
|
s.description = "Gyoku translates Ruby Hashes to XML"
|
13
|
-
s.required_ruby_version = ">= 3.
|
13
|
+
s.required_ruby_version = ">= 3.1"
|
14
14
|
|
15
15
|
s.license = "MIT"
|
16
16
|
|
17
17
|
s.add_dependency "builder", ">= 2.1.2"
|
18
|
-
s.add_dependency "rexml", "~> 3.
|
18
|
+
s.add_dependency "rexml", "~> 3.4"
|
19
19
|
|
20
20
|
s.add_development_dependency "rake"
|
21
21
|
s.add_development_dependency "rspec"
|
22
22
|
s.add_development_dependency "standard"
|
23
|
+
s.add_development_dependency "fiddle"
|
24
|
+
s.add_development_dependency "cookstyle", ">= 8.0.0"
|
23
25
|
|
24
26
|
s.files = `git ls-files`.split("\n")
|
25
27
|
|
@@ -2,7 +2,7 @@ module Gyoku
|
|
2
2
|
module Array
|
3
3
|
module_function
|
4
4
|
|
5
|
-
NESTED_ELEMENT_NAME = "element"
|
5
|
+
NESTED_ELEMENT_NAME = "element".freeze
|
6
6
|
|
7
7
|
# Builds XML and prettifies it if +pretty_print+ option is set to +true+
|
8
8
|
def to_xml(array, key, escape_xml = true, attributes = {}, options = {})
|
@@ -64,13 +64,13 @@ module Gyoku
|
|
64
64
|
def iterate_array(xml, array, attributes, &block)
|
65
65
|
array.each_with_index do |item, index|
|
66
66
|
attrs = if item.respond_to?(:keys)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
67
|
+
item.each_with_object({}) do |v, st|
|
68
|
+
k = v[0].to_s
|
69
|
+
st[k[1..]] = v[1].to_s if Hash.explicit_attribute?(k)
|
70
|
+
end
|
71
|
+
else
|
72
|
+
{}
|
73
|
+
end
|
74
74
|
yield xml, item, tag_attributes(attributes, index).merge(attrs), index
|
75
75
|
end
|
76
76
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require "builder"
|
2
|
-
require "gyoku/prettifier"
|
3
|
-
require "gyoku/array"
|
4
|
-
require "gyoku/xml_key"
|
5
|
-
require "gyoku/xml_value"
|
2
|
+
require "chef-gyoku/prettifier"
|
3
|
+
require "chef-gyoku/array"
|
4
|
+
require "chef-gyoku/xml_key"
|
5
|
+
require "chef-gyoku/xml_value"
|
6
6
|
|
7
7
|
module Gyoku
|
8
8
|
module Hash
|
@@ -1,22 +1,22 @@
|
|
1
1
|
module Gyoku
|
2
2
|
module XMLKey
|
3
3
|
class << self
|
4
|
-
CAMELCASE = lambda { |key| key.gsub(
|
4
|
+
CAMELCASE = lambda { |key| key.gsub(%r{/(.?)}) { |m| "::#{m[-1].upcase}" }.gsub(/(?:^|_)(.)/) { |m| m[-1].upcase } }
|
5
5
|
LOWER_CAMELCASE = lambda { |key| key[0].chr.downcase + CAMELCASE.call(key)[1..] }
|
6
|
-
UPCASE = lambda
|
6
|
+
UPCASE = lambda(&:upcase)
|
7
7
|
|
8
8
|
FORMULAS = {
|
9
9
|
lower_camelcase: lambda { |key| LOWER_CAMELCASE.call(key) },
|
10
10
|
camelcase: lambda { |key| CAMELCASE.call(key) },
|
11
11
|
upcase: lambda { |key| UPCASE.call(key) },
|
12
|
-
none: lambda { |key| key }
|
13
|
-
}
|
12
|
+
none: lambda { |key| key },
|
13
|
+
}.freeze
|
14
14
|
|
15
15
|
# Converts a given +object+ with +options+ to an XML key.
|
16
16
|
def create(key, options = {})
|
17
17
|
xml_key = chop_special_characters key.to_s
|
18
18
|
|
19
|
-
if unqualified = unqualify?(xml_key)
|
19
|
+
if (unqualified = unqualify?(xml_key))
|
20
20
|
xml_key = xml_key.split(":").last
|
21
21
|
end
|
22
22
|
|
@@ -37,14 +37,14 @@ module Gyoku
|
|
37
37
|
|
38
38
|
defined_key = options[:key_to_convert]
|
39
39
|
key_converter = if !defined_key.nil? && (defined_key == xml_key)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
options[:key_converter]
|
41
|
+
elsif !defined_key.nil?
|
42
|
+
:lower_camelcase
|
43
|
+
elsif options[:except] == xml_key
|
44
|
+
:lower_camelcase
|
45
|
+
else
|
46
|
+
options[:key_converter] || :lower_camelcase
|
47
|
+
end
|
48
48
|
FORMULAS[key_converter]
|
49
49
|
end
|
50
50
|
|
@@ -1,17 +1,17 @@
|
|
1
|
-
require "cgi"
|
1
|
+
require "cgi" unless defined?(CGI)
|
2
2
|
require "date"
|
3
3
|
|
4
4
|
module Gyoku
|
5
5
|
module XMLValue
|
6
6
|
class << self
|
7
7
|
# xs:date format
|
8
|
-
XS_DATE_FORMAT = "%Y-%m-%d"
|
8
|
+
XS_DATE_FORMAT = "%Y-%m-%d".freeze
|
9
9
|
|
10
10
|
# xs:time format
|
11
|
-
XS_TIME_FORMAT = "%H:%M:%S"
|
11
|
+
XS_TIME_FORMAT = "%H:%M:%S".freeze
|
12
12
|
|
13
13
|
# xs:dateTime format
|
14
|
-
XS_DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S%Z"
|
14
|
+
XS_DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S%Z".freeze
|
15
15
|
|
16
16
|
# Converts a given +object+ to an XML value.
|
17
17
|
def create(object, escape_xml = true, options = {})
|
@@ -3,14 +3,14 @@ require "spec_helper"
|
|
3
3
|
describe Gyoku::Array do
|
4
4
|
describe ".to_xml" do
|
5
5
|
it "returns the XML for an Array of Hashes" do
|
6
|
-
array = [{name: "adam"}, {name: "eve"}]
|
6
|
+
array = [{ name: "adam" }, { name: "eve" }]
|
7
7
|
result = "<user><name>adam</name></user><user><name>eve</name></user>"
|
8
8
|
|
9
9
|
expect(to_xml(array, "user")).to eq(result)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "returns the XML for an Array of Hashes unwrapped" do
|
13
|
-
array = [{name: "adam"}, {name: "eve"}]
|
13
|
+
array = [{ name: "adam" }, { name: "eve" }]
|
14
14
|
result = "<user><name>adam</name><name>eve</name></user>"
|
15
15
|
|
16
16
|
expect(to_xml(array, "user", true, {}, unwrap: true)).to eq(result)
|
@@ -38,39 +38,39 @@ describe Gyoku::Array do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "adds attributes to a given tag" do
|
41
|
-
array =
|
41
|
+
array = %w{adam eve}
|
42
42
|
result = '<value active="true">adam</value><value active="true">eve</value>'
|
43
43
|
|
44
44
|
expect(to_xml(array, "value", :escape_xml, active: true)).to eq(result)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "adds attributes to tags when :unwrap is true" do
|
48
|
-
array = [{item: "abc"}]
|
48
|
+
array = [{ item: "abc" }]
|
49
49
|
key = "items"
|
50
50
|
escape_xml = :escape_xml
|
51
|
-
attributes = {"amount" => "1"}
|
52
|
-
options = {unwrap: true}
|
51
|
+
attributes = { "amount" => "1" }
|
52
|
+
options = { unwrap: true }
|
53
53
|
result = "<items amount=\"1\"><item>abc</item></items>"
|
54
54
|
|
55
55
|
expect(to_xml(array, key, escape_xml, attributes, options)).to eq result
|
56
56
|
end
|
57
57
|
|
58
58
|
it "adds attributes to duplicate tags" do
|
59
|
-
array =
|
59
|
+
array = %w{adam eve}
|
60
60
|
result = '<value id="1">adam</value><value id="2">eve</value>'
|
61
61
|
|
62
62
|
expect(to_xml(array, "value", :escape_xml, id: [1, 2])).to eq(result)
|
63
63
|
end
|
64
64
|
|
65
65
|
it "skips attribute for element without attributes if there are fewer attributes than elements" do
|
66
|
-
array =
|
66
|
+
array = %w{adam eve serpent}
|
67
67
|
result = '<value id="1">adam</value><value id="2">eve</value><value>serpent</value>'
|
68
68
|
|
69
69
|
expect(to_xml(array, "value", :escape_xml, id: [1, 2])).to eq(result)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "handles nested Arrays" do
|
73
|
-
array = [
|
73
|
+
array = [%w{one two}]
|
74
74
|
result = "<value><element>one</element><element>two</element></value>"
|
75
75
|
|
76
76
|
expect(to_xml(array, "value")).to eq(result)
|
@@ -79,16 +79,16 @@ describe Gyoku::Array do
|
|
79
79
|
context "when :pretty_print option is set to true" do
|
80
80
|
context "when :unwrap option is set to true" do
|
81
81
|
it "returns prettified xml" do
|
82
|
-
array = ["one", "two", {"three" => "four"}]
|
83
|
-
options = {pretty_print: true, unwrap: true}
|
82
|
+
array = ["one", "two", { "three" => "four" }]
|
83
|
+
options = { pretty_print: true, unwrap: true }
|
84
84
|
result = "<test>\n <test>one</test>\n <test>two</test>\n <three>four</three>\n</test>"
|
85
85
|
expect(to_xml(array, "test", true, {}, options)).to eq(result)
|
86
86
|
end
|
87
87
|
|
88
88
|
context "when :indent option is specified" do
|
89
89
|
it "returns prettified xml with specified indent" do
|
90
|
-
array = ["one", "two", {"three" => "four"}]
|
91
|
-
options = {pretty_print: true, indent: 3, unwrap: true}
|
90
|
+
array = ["one", "two", { "three" => "four" }]
|
91
|
+
options = { pretty_print: true, indent: 3, unwrap: true }
|
92
92
|
result = "<test>\n <test>one</test>\n <test>two</test>\n <three>four</three>\n</test>"
|
93
93
|
expect(to_xml(array, "test", true, {}, options)).to eq(result)
|
94
94
|
end
|
@@ -96,8 +96,8 @@ describe Gyoku::Array do
|
|
96
96
|
|
97
97
|
context "when :compact option is specified" do
|
98
98
|
it "returns prettified xml with specified compact mode" do
|
99
|
-
array = ["one", {"two" => "three"}]
|
100
|
-
options = {pretty_print: true, compact: false, unwrap: true}
|
99
|
+
array = ["one", { "two" => "three" }]
|
100
|
+
options = { pretty_print: true, compact: false, unwrap: true }
|
101
101
|
result = "<test>\n <test>\n one\n </test>\n <two>\n three \n </two>\n</test>"
|
102
102
|
expect(to_xml(array, "test", true, {}, options)).to eq(result)
|
103
103
|
end
|
@@ -106,8 +106,8 @@ describe Gyoku::Array do
|
|
106
106
|
|
107
107
|
context "when :unwrap option is not set" do
|
108
108
|
it "returns non-prettified xml" do
|
109
|
-
array = ["one", "two", {"three" => "four"}]
|
110
|
-
options = {pretty_print: true}
|
109
|
+
array = ["one", "two", { "three" => "four" }]
|
110
|
+
options = { pretty_print: true }
|
111
111
|
result = "<test>one</test><test>two</test><test><three>four</three></test>"
|
112
112
|
expect(to_xml(array, "test", true, {}, options)).to eq(result)
|
113
113
|
end
|
@@ -8,29 +8,29 @@ describe Gyoku::Hash do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "for a nested Hash" do
|
11
|
-
expect(to_xml(some: {new: "user"})).to eq("<some><new>user</new></some>")
|
11
|
+
expect(to_xml(some: { new: "user" })).to eq("<some><new>user</new></some>")
|
12
12
|
end
|
13
13
|
|
14
14
|
context "with key_converter" do
|
15
15
|
it "expect all keys change" do
|
16
|
-
expect(to_xml({some: {new: "user"}}, {key_converter: :camelcase})).to eq("<Some><New>user</New></Some>")
|
16
|
+
expect(to_xml({ some: { new: "user" } }, { key_converter: :camelcase })).to eq("<Some><New>user</New></Some>")
|
17
17
|
end
|
18
18
|
|
19
19
|
it "and key_to_convert option should change only key" do
|
20
|
-
hash = {some: {new: "user", age: 20}}
|
21
|
-
options = {key_converter: :camelcase, key_to_convert: "some"}
|
20
|
+
hash = { some: { new: "user", age: 20 } }
|
21
|
+
options = { key_converter: :camelcase, key_to_convert: "some" }
|
22
22
|
result = "<Some><new>user</new><age>20</age></Some>"
|
23
23
|
expect(to_xml(hash, options)).to eq(result)
|
24
24
|
|
25
|
-
hash = {some: {new: "user", age: 20}}
|
26
|
-
options = {key_converter: :camelcase, key_to_convert: "new"}
|
25
|
+
hash = { some: { new: "user", age: 20 } }
|
26
|
+
options = { key_converter: :camelcase, key_to_convert: "new" }
|
27
27
|
result = "<some><New>user</New><age>20</age></some>"
|
28
28
|
expect(to_xml(hash, options)).to eq(result)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "with except option, dont convert this key" do
|
32
|
-
hash = {some: {new: "user", age: 20}}
|
33
|
-
options = {key_converter: :camelcase, except: "some"}
|
32
|
+
hash = { some: { new: "user", age: 20 } }
|
33
|
+
options = { key_converter: :camelcase, except: "some" }
|
34
34
|
result = "<some><New>user</New><Age>20</Age></some>"
|
35
35
|
expect(to_xml(hash, options)).to eq(result)
|
36
36
|
end
|
@@ -44,26 +44,26 @@ describe Gyoku::Hash do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "for a Hash containing an Array" do
|
47
|
-
expect(to_xml(some:
|
47
|
+
expect(to_xml(some: %w{user gorilla})).to eq("<some>user</some><some>gorilla</some>")
|
48
48
|
end
|
49
49
|
|
50
50
|
it "for a Hash containing an Array of Hashes" do
|
51
|
-
expect(to_xml(some: [{new: "user"}, {old: "gorilla"}]))
|
51
|
+
expect(to_xml(some: [{ new: "user" }, { old: "gorilla" }]))
|
52
52
|
.to eq("<some><new>user</new></some><some><old>gorilla</old></some>")
|
53
53
|
end
|
54
54
|
|
55
55
|
context "when :pretty_print option is set to true" do
|
56
56
|
it "returns prettified xml" do
|
57
|
-
hash = {some: {user: {name: "John", groups:
|
58
|
-
options = {pretty_print: true}
|
57
|
+
hash = { some: { user: { name: "John", groups: %w{admin editor} } } }
|
58
|
+
options = { pretty_print: true }
|
59
59
|
result = "<some>\n <user>\n <name>John</name>\n <groups>admin</groups>\n <groups>editor</groups>\n </user>\n</some>"
|
60
60
|
expect(to_xml(hash, options)).to eq(result)
|
61
61
|
end
|
62
62
|
|
63
63
|
context "when :indent option is specified" do
|
64
64
|
it "returns prettified xml with specified indent" do
|
65
|
-
hash = {some: {user: {name: "John"}}}
|
66
|
-
options = {pretty_print: true, indent: 4}
|
65
|
+
hash = { some: { user: { name: "John" } } }
|
66
|
+
options = { pretty_print: true, indent: 4 }
|
67
67
|
result = "<some>\n <user>\n <name>John</name>\n </user>\n</some>"
|
68
68
|
expect(to_xml(hash, options)).to eq(result)
|
69
69
|
end
|
@@ -71,8 +71,8 @@ describe Gyoku::Hash do
|
|
71
71
|
|
72
72
|
context "when :compact option is specified" do
|
73
73
|
it "returns prettified xml with specified compact mode" do
|
74
|
-
hash = {some: {user: {name: "John"}}}
|
75
|
-
options = {pretty_print: true, compact: false}
|
74
|
+
hash = { some: { user: { name: "John" } } }
|
75
|
+
options = { pretty_print: true, compact: false }
|
76
76
|
result = "<some>\n <user>\n <name>\n John\n </name>\n </user>\n</some>"
|
77
77
|
expect(to_xml(hash, options)).to eq(result)
|
78
78
|
end
|
@@ -126,74 +126,74 @@ describe Gyoku::Hash do
|
|
126
126
|
end
|
127
127
|
|
128
128
|
it "defaults to escape special characters" do
|
129
|
-
result = to_xml(some: {nested: "<tag />"}, tag: "<tag />")
|
129
|
+
result = to_xml(some: { nested: "<tag />" }, tag: "<tag />")
|
130
130
|
expect(result).to include("<tag><tag /></tag>")
|
131
131
|
expect(result).to include("<some><nested><tag /></nested></some>")
|
132
132
|
end
|
133
133
|
|
134
134
|
it "does not escape special characters for keys marked with an exclamation mark" do
|
135
|
-
result = to_xml(some: {nested!: "<tag />"}, tag!: "<tag />")
|
135
|
+
result = to_xml(some: { nested!: "<tag />" }, tag!: "<tag />")
|
136
136
|
expect(result).to include("<tag><tag /></tag>")
|
137
137
|
expect(result).to include("<some><nested><tag /></nested></some>")
|
138
138
|
end
|
139
139
|
|
140
140
|
it "preserves the order of Hash keys and values specified through :order!" do
|
141
|
-
hash = {find_user: {name: "Lucy", id: 666, order!:
|
141
|
+
hash = { find_user: { name: "Lucy", id: 666, order!: %i{id name} } }
|
142
142
|
result = "<findUser><id>666</id><name>Lucy</name></findUser>"
|
143
143
|
expect(to_xml(hash)).to eq(result)
|
144
144
|
|
145
|
-
hash = {find_user: {mname: "in the", lname: "Sky", fname: "Lucy", order!:
|
145
|
+
hash = { find_user: { mname: "in the", lname: "Sky", fname: "Lucy", order!: %i{fname mname lname} } }
|
146
146
|
result = "<findUser><fname>Lucy</fname><mname>in the</mname><lname>Sky</lname></findUser>"
|
147
147
|
expect(to_xml(hash)).to eq(result)
|
148
148
|
end
|
149
149
|
|
150
150
|
it "preserves the order of Hash keys and values specified through 'order!' (as a string key)" do
|
151
|
-
hash = {find_user: {:name => "Lucy", :id => 666, "order!" =>
|
151
|
+
hash = { find_user: { :name => "Lucy", :id => 666, "order!" => %i{id name} } }
|
152
152
|
result = "<findUser><id>666</id><name>Lucy</name></findUser>"
|
153
153
|
expect(to_xml(hash)).to eq(result)
|
154
154
|
|
155
|
-
hash = {find_user: {:mname => "in the", :lname => "Sky", :fname => "Lucy", "order!" =>
|
155
|
+
hash = { find_user: { :mname => "in the", :lname => "Sky", :fname => "Lucy", "order!" => %i{fname mname lname} } }
|
156
156
|
result = "<findUser><fname>Lucy</fname><mname>in the</mname><lname>Sky</lname></findUser>"
|
157
157
|
expect(to_xml(hash)).to eq(result)
|
158
158
|
end
|
159
159
|
|
160
160
|
it "uses :order! symbol values for ordering but leaves the string key 'order!' if both are present" do
|
161
|
-
hash = {find_user: {:name => "Lucy", :id => 666, "order!" => "value", :order! => [:id, :name, "order!"]}}
|
161
|
+
hash = { find_user: { :name => "Lucy", :id => 666, "order!" => "value", :order! => [:id, :name, "order!"] } }
|
162
162
|
result = "<findUser><id>666</id><name>Lucy</name><order>value</order></findUser>"
|
163
163
|
expect(to_xml(hash)).to eq(result)
|
164
164
|
end
|
165
165
|
|
166
166
|
it "raises if the :order! Array is missing Hash keys" do
|
167
|
-
hash = {name: "Lucy", id: 666, order!: [:name]}
|
167
|
+
hash = { name: "Lucy", id: 666, order!: [:name] }
|
168
168
|
expect { to_xml(hash) }.to raise_error(ArgumentError, "Missing elements in :order! [:id]")
|
169
169
|
end
|
170
170
|
|
171
171
|
it "raises if the :order! Array contains missing Hash keys" do
|
172
|
-
hash = {by_name: {first_name: "Lucy", last_name: "Sky", order!:
|
172
|
+
hash = { by_name: { first_name: "Lucy", last_name: "Sky", order!: %i{first_name middle_name last_name} } }
|
173
173
|
expect { to_xml(hash) }.to raise_error(ArgumentError, "Spurious elements in :order! [:middle_name]")
|
174
174
|
end
|
175
175
|
|
176
176
|
it "adds attributes to Hash keys specified through :attributes!" do
|
177
|
-
hash = {find_user: {person: "Lucy", attributes!: {person: {id: 666}}}}
|
177
|
+
hash = { find_user: { person: "Lucy", attributes!: { person: { id: 666 } } } }
|
178
178
|
result = '<findUser><person id="666">Lucy</person></findUser>'
|
179
179
|
expect(to_xml(hash)).to eq(result)
|
180
180
|
|
181
|
-
hash = {find_user: {person: "Lucy", attributes!: {person: {id: 666, city: "Hamburg"}}}}
|
181
|
+
hash = { find_user: { person: "Lucy", attributes!: { person: { id: 666, city: "Hamburg" } } } }
|
182
182
|
expect(to_xml(hash)).to include('id="666"', 'city="Hamburg"')
|
183
183
|
end
|
184
184
|
|
185
185
|
it "adds attributes to duplicate Hash keys specified through :attributes!" do
|
186
|
-
hash = {find_user: {person:
|
186
|
+
hash = { find_user: { person: %w{Lucy Anna}, attributes!: { person: { id: [1, 3] } } } }
|
187
187
|
result = '<findUser><person id="1">Lucy</person><person id="3">Anna</person></findUser>'
|
188
188
|
expect(to_xml(hash)).to eq(result)
|
189
189
|
|
190
|
-
hash = {find_user: {person:
|
190
|
+
hash = { find_user: { person: %w{Lucy Anna}, attributes!: { person: { active: "true" } } } }
|
191
191
|
result = '<findUser><person active="true">Lucy</person><person active="true">Anna</person></findUser>'
|
192
192
|
expect(to_xml(hash)).to eq(result)
|
193
193
|
end
|
194
194
|
|
195
195
|
it "skips attribute for element without attributes if there are fewer attributes than elements" do
|
196
|
-
hash = {find_user: {person:
|
196
|
+
hash = { find_user: { person: %w{Lucy Anna Beth}, attributes!: { person: { id: [1, 3] } } } }
|
197
197
|
result = '<findUser><person id="1">Lucy</person><person id="3">Anna</person><person>Beth</person></findUser>'
|
198
198
|
expect(to_xml(hash)).to eq(result)
|
199
199
|
end
|
@@ -201,7 +201,7 @@ describe Gyoku::Hash do
|
|
201
201
|
it "adds attributes to self-closing tags" do
|
202
202
|
hash = {
|
203
203
|
"category/" => "",
|
204
|
-
:attributes! => {"category/" => {id: 1}}
|
204
|
+
:attributes! => { "category/" => { id: 1 } },
|
205
205
|
}
|
206
206
|
|
207
207
|
expect(to_xml(hash)).to eq('<category id="1"/>')
|
@@ -211,8 +211,8 @@ describe Gyoku::Hash do
|
|
211
211
|
hash = {
|
212
212
|
"category" => {
|
213
213
|
:content! => "users",
|
214
|
-
:@id => 1
|
215
|
-
}
|
214
|
+
:@id => 1,
|
215
|
+
},
|
216
216
|
}
|
217
217
|
expect(to_xml(hash)).to eq('<category id="1">users</category>')
|
218
218
|
end
|
@@ -220,8 +220,8 @@ describe Gyoku::Hash do
|
|
220
220
|
it "recognizes @attribute => value along :attributes! in selfclosed tags" do
|
221
221
|
hash = {
|
222
222
|
"category/" => {
|
223
|
-
:@id => 1
|
224
|
-
}
|
223
|
+
:@id => 1,
|
224
|
+
},
|
225
225
|
}
|
226
226
|
expect(to_xml(hash)).to eq('<category id="1"/>')
|
227
227
|
end
|
@@ -229,14 +229,14 @@ describe Gyoku::Hash do
|
|
229
229
|
it ":@attribute => value takes over :attributes!" do
|
230
230
|
hash = {
|
231
231
|
"category/" => {
|
232
|
-
:@id => 1
|
232
|
+
:@id => 1,
|
233
233
|
},
|
234
234
|
:attributes! => {
|
235
235
|
"category/" => {
|
236
236
|
"id" => 2, # will be ignored
|
237
|
-
"type" => "admins"
|
238
|
-
}
|
239
|
-
}
|
237
|
+
"type" => "admins",
|
238
|
+
},
|
239
|
+
},
|
240
240
|
}
|
241
241
|
# attribute order is undefined
|
242
242
|
expect(['<category id="1" type="admins"/>', '<category type="admins" id="1"/>']).to include to_xml(hash)
|
@@ -244,14 +244,14 @@ describe Gyoku::Hash do
|
|
244
244
|
# with symbols
|
245
245
|
hash = {
|
246
246
|
"category/" => {
|
247
|
-
:@id => 1
|
247
|
+
:@id => 1,
|
248
248
|
},
|
249
249
|
:attributes! => {
|
250
250
|
"category/" => {
|
251
251
|
id: 2, # will be ignored
|
252
|
-
type: "admins"
|
253
|
-
}
|
254
|
-
}
|
252
|
+
type: "admins",
|
253
|
+
},
|
254
|
+
},
|
255
255
|
}
|
256
256
|
expect(['<category id="1" type="admins"/>', '<category type="admins" id="1"/>']).to include to_xml(hash)
|
257
257
|
end
|
@@ -259,8 +259,8 @@ describe Gyoku::Hash do
|
|
259
259
|
it "recognizes :content! => value as tag content" do
|
260
260
|
hash = {
|
261
261
|
"category" => {
|
262
|
-
content!: "users"
|
263
|
-
}
|
262
|
+
content!: "users",
|
263
|
+
},
|
264
264
|
}
|
265
265
|
expect(to_xml(hash)).to eq("<category>users</category>")
|
266
266
|
end
|
@@ -268,8 +268,8 @@ describe Gyoku::Hash do
|
|
268
268
|
it "recognizes :content! => value as tag content with value Fixnum" do
|
269
269
|
hash = {
|
270
270
|
"category" => {
|
271
|
-
content!: 666
|
272
|
-
}
|
271
|
+
content!: 666,
|
272
|
+
},
|
273
273
|
}
|
274
274
|
expect(to_xml(hash)).to eq("<category>666</category>")
|
275
275
|
end
|
@@ -277,8 +277,8 @@ describe Gyoku::Hash do
|
|
277
277
|
it "recognizes :content! => value as tag content with value true" do
|
278
278
|
hash = {
|
279
279
|
"category" => {
|
280
|
-
content!: true
|
281
|
-
}
|
280
|
+
content!: true,
|
281
|
+
},
|
282
282
|
}
|
283
283
|
expect(to_xml(hash)).to eq("<category>true</category>")
|
284
284
|
end
|
@@ -286,8 +286,8 @@ describe Gyoku::Hash do
|
|
286
286
|
it "recognizes :content! => value as tag content with value false" do
|
287
287
|
hash = {
|
288
288
|
"category" => {
|
289
|
-
content!: false
|
290
|
-
}
|
289
|
+
content!: false,
|
290
|
+
},
|
291
291
|
}
|
292
292
|
expect(to_xml(hash)).to eq("<category>false</category>")
|
293
293
|
end
|
@@ -295,8 +295,8 @@ describe Gyoku::Hash do
|
|
295
295
|
it "recognizes :content! => value as tag content with value DateTime" do
|
296
296
|
hash = {
|
297
297
|
"before" => {
|
298
|
-
content!: DateTime.new(2012, 0o3, 22, 16, 22, 33)
|
299
|
-
}
|
298
|
+
content!: DateTime.new(2012, 0o3, 22, 16, 22, 33),
|
299
|
+
},
|
300
300
|
}
|
301
301
|
expect(to_xml(hash)).to eq("<before>2012-03-22T16:22:33+00:00</before>")
|
302
302
|
end
|
@@ -304,59 +304,59 @@ describe Gyoku::Hash do
|
|
304
304
|
it "ignores :content! if self-closing mark present" do
|
305
305
|
hash = {
|
306
306
|
"category/" => {
|
307
|
-
content!: "users"
|
308
|
-
}
|
307
|
+
content!: "users",
|
308
|
+
},
|
309
309
|
}
|
310
310
|
expect(to_xml(hash)).to eq("<category/>")
|
311
311
|
end
|
312
312
|
|
313
313
|
it "recognizes array of attributes" do
|
314
314
|
hash = {
|
315
|
-
"category" => [{:@name => "one"}, {:@name => "two"}]
|
315
|
+
"category" => [{ :@name => "one" }, { :@name => "two" }],
|
316
316
|
}
|
317
317
|
expect(to_xml(hash)).to eq('<category name="one"></category><category name="two"></category>')
|
318
318
|
|
319
319
|
# issue #31.
|
320
320
|
hash = {
|
321
|
-
:order! =>
|
322
|
-
"foo" => {:@foo => "foo"},
|
323
|
-
"bar" => {:@bar => "bar", "baz" => {}}
|
321
|
+
:order! => %w{foo bar},
|
322
|
+
"foo" => { :@foo => "foo" },
|
323
|
+
"bar" => { :@bar => "bar", "baz" => {} },
|
324
324
|
}
|
325
325
|
expect(to_xml(hash)).to eq('<foo foo="foo"></foo><bar bar="bar"><baz></baz></bar>')
|
326
326
|
end
|
327
327
|
|
328
328
|
it "recognizes array of attributes with content in each" do
|
329
329
|
hash = {
|
330
|
-
"foo" => [{:@name => "bar", :content! => "gyoku"}, {:@name => "baz", :@some => "attr", :content! => "rocks!"}]
|
330
|
+
"foo" => [{ :@name => "bar", :content! => "gyoku" }, { :@name => "baz", :@some => "attr", :content! => "rocks!" }],
|
331
331
|
}
|
332
332
|
|
333
333
|
expect([
|
334
334
|
'<foo name="bar">gyoku</foo><foo name="baz" some="attr">rocks!</foo>',
|
335
|
-
'<foo name="bar">gyoku</foo><foo some="attr" name="baz">rocks!</foo>'
|
335
|
+
'<foo name="bar">gyoku</foo><foo some="attr" name="baz">rocks!</foo>',
|
336
336
|
]).to include to_xml(hash)
|
337
337
|
end
|
338
338
|
|
339
339
|
it "recognizes array of attributes but ignores content in each if selfclosing" do
|
340
340
|
hash = {
|
341
|
-
"foo/" => [{:@name => "bar", :content! => "gyoku"}, {:@name => "baz", :@some => "attr", :content! => "rocks!"}]
|
341
|
+
"foo/" => [{ :@name => "bar", :content! => "gyoku" }, { :@name => "baz", :@some => "attr", :content! => "rocks!" }],
|
342
342
|
}
|
343
343
|
|
344
344
|
expect([
|
345
345
|
'<foo name="bar"/><foo name="baz" some="attr"/>',
|
346
|
-
'<foo name="bar"/><foo some="attr" name="baz"/>'
|
346
|
+
'<foo name="bar"/><foo some="attr" name="baz"/>',
|
347
347
|
]).to include to_xml(hash)
|
348
348
|
end
|
349
349
|
|
350
350
|
it "recognizes array of attributes with selfclosing tag" do
|
351
351
|
hash = {
|
352
|
-
"category/" => [{:@name => "one"}, {:@name => "two"}]
|
352
|
+
"category/" => [{ :@name => "one" }, { :@name => "two" }],
|
353
353
|
}
|
354
354
|
expect(to_xml(hash)).to eq('<category name="one"/><category name="two"/>')
|
355
355
|
end
|
356
356
|
|
357
357
|
context "with :element_form_default set to :qualified and a :namespace" do
|
358
358
|
it "adds the given :namespace to every element" do
|
359
|
-
hash = {:first => {"first_name" => "Lucy"}, ":second" => {":first_name": "Anna"}, "v2:third" => {"v2:firstName" => "Danie"}}
|
359
|
+
hash = { :first => { "first_name" => "Lucy" }, ":second" => { ":first_name": "Anna" }, "v2:third" => { "v2:firstName" => "Danie" } }
|
360
360
|
result = to_xml hash, element_form_default: :qualified, namespace: :v1
|
361
361
|
|
362
362
|
expect(result).to include(
|
@@ -367,7 +367,7 @@ describe Gyoku::Hash do
|
|
367
367
|
end
|
368
368
|
|
369
369
|
it "adds given :namespace to every element in an array" do
|
370
|
-
hash = {array: [first: "Lucy", second: "Anna"]}
|
370
|
+
hash = { array: [first: "Lucy", second: "Anna"] }
|
371
371
|
result = to_xml hash, element_form_default: :qualified, namespace: :v1
|
372
372
|
|
373
373
|
expect(result).to include("<v1:array>", "<v1:first>Lucy</v1:first>", "<v1:second>Anna</v1:second>")
|
@@ -379,12 +379,12 @@ describe Gyoku::Hash do
|
|
379
379
|
persons: {
|
380
380
|
first: "Lucy",
|
381
381
|
second: "Anna",
|
382
|
-
order!:
|
383
|
-
attributes!: {first: {first: true}}
|
382
|
+
order!: %i{second first},
|
383
|
+
attributes!: { first: { first: true } },
|
384
384
|
},
|
385
|
-
countries:
|
386
|
-
order!:
|
387
|
-
attributes!: {countries: {array: true}}
|
385
|
+
countries: %i{de us},
|
386
|
+
order!: %i{countries persons},
|
387
|
+
attributes!: { countries: { array: true } },
|
388
388
|
}
|
389
389
|
|
390
390
|
to_xml(hash)
|
@@ -393,20 +393,20 @@ describe Gyoku::Hash do
|
|
393
393
|
persons: {
|
394
394
|
first: "Lucy",
|
395
395
|
second: "Anna",
|
396
|
-
order!:
|
397
|
-
attributes!: {first: {first: true}}
|
396
|
+
order!: %i{second first},
|
397
|
+
attributes!: { first: { first: true } },
|
398
398
|
},
|
399
|
-
countries:
|
400
|
-
order!:
|
401
|
-
attributes!: {countries: {array: true}}
|
399
|
+
countries: %i{de us},
|
400
|
+
order!: %i{countries persons},
|
401
|
+
attributes!: { countries: { array: true } },
|
402
402
|
})
|
403
403
|
end
|
404
404
|
end
|
405
405
|
|
406
406
|
it "doesn't modify original hash parameter by deleting its attribute keys" do
|
407
|
-
hash = {person: {name: "Johnny", surname: "Bravo", "@xsi:type": "People"}}
|
407
|
+
hash = { person: { name: "Johnny", surname: "Bravo", "@xsi:type": "People" } }
|
408
408
|
to_xml(hash)
|
409
|
-
expect(hash).to eq({person: {name: "Johnny", surname: "Bravo", "@xsi:type": "People"}})
|
409
|
+
expect(hash).to eq({ person: { name: "Johnny", surname: "Bravo", "@xsi:type": "People" } })
|
410
410
|
end
|
411
411
|
|
412
412
|
describe ".explicit_attribute?" do
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Gyoku::Prettifier do
|
4
4
|
describe "#prettify" do
|
5
5
|
context "when xml is valid" do
|
6
|
-
let!(:xml) { Gyoku::Hash.build_xml(test: {pretty: "xml"}) }
|
6
|
+
let!(:xml) { Gyoku::Hash.build_xml(test: { pretty: "xml" }) }
|
7
7
|
|
8
8
|
it "returns prettified xml" do
|
9
9
|
expect(subject.prettify(xml)).to eql("<test>\n <pretty>xml</pretty>\n</test>")
|
@@ -11,7 +11,7 @@ describe Gyoku::Prettifier do
|
|
11
11
|
|
12
12
|
context "when indent option is specified" do
|
13
13
|
it "returns prettified xml with indent" do
|
14
|
-
options = {indent: 3}
|
14
|
+
options = { indent: 3 }
|
15
15
|
subject = Gyoku::Prettifier.new(options)
|
16
16
|
expect(subject.prettify(xml)).to eql("<test>\n <pretty>xml</pretty>\n</test>")
|
17
17
|
end
|
@@ -19,7 +19,7 @@ describe Gyoku::Prettifier do
|
|
19
19
|
|
20
20
|
context "when compact option is specified" do
|
21
21
|
it "returns prettified xml with indent" do
|
22
|
-
options = {compact: false}
|
22
|
+
options = { compact: false }
|
23
23
|
subject = Gyoku::Prettifier.new(options)
|
24
24
|
expect(subject.prettify(xml)).to eql("<test>\n <pretty>\n xml\n </pretty>\n</test>")
|
25
25
|
end
|
@@ -28,7 +28,7 @@ describe Gyoku::Prettifier do
|
|
28
28
|
|
29
29
|
context "when xml is not valid" do
|
30
30
|
let!(:xml) do
|
31
|
-
Gyoku::Array.build_xml(
|
31
|
+
Gyoku::Array.build_xml(%w{one two}, "test")
|
32
32
|
end
|
33
33
|
|
34
34
|
it "raises an error" do
|
@@ -23,31 +23,31 @@ describe Gyoku::XMLKey do
|
|
23
23
|
it "should replace / with ::, and turn snake case into camel case" do
|
24
24
|
input = :"hello_world_bob/how_are_you|there:foo^bar"
|
25
25
|
expected_output = "HelloWorldBob::HowAreYou|there:foo^bar"
|
26
|
-
expect(create(input, {key_converter: :camelcase})).to eq(expected_output)
|
26
|
+
expect(create(input, { key_converter: :camelcase })).to eq(expected_output)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
context "with key_converter" do
|
31
31
|
it "accepts lambda converters" do
|
32
|
-
expect(create(:some_text, {key_converter: lambda
|
32
|
+
expect(create(:some_text, { key_converter: lambda(&:reverse) })).to eq("txet_emos")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "convert symbol to the specified type" do
|
36
|
-
expect(create(:some_text, {key_converter: :camelcase})).to eq("SomeText")
|
37
|
-
expect(create(:some_text, {key_converter: :upcase})).to eq("SOME_TEXT")
|
38
|
-
expect(create(:some_text, {key_converter: :none})).to eq("some_text")
|
36
|
+
expect(create(:some_text, { key_converter: :camelcase })).to eq("SomeText")
|
37
|
+
expect(create(:some_text, { key_converter: :upcase })).to eq("SOME_TEXT")
|
38
|
+
expect(create(:some_text, { key_converter: :none })).to eq("some_text")
|
39
39
|
end
|
40
40
|
|
41
41
|
it "when key_to_convert is defined, convert only this key" do
|
42
|
-
options = {key_converter: :camelcase, key_to_convert: "somekey"}
|
42
|
+
options = { key_converter: :camelcase, key_to_convert: "somekey" }
|
43
43
|
expect(create(:some_key, options)).to eq("someKey")
|
44
44
|
|
45
|
-
options = {key_converter: :camelcase, key_to_convert: "some_key"}
|
45
|
+
options = { key_converter: :camelcase, key_to_convert: "some_key" }
|
46
46
|
expect(create(:some_key, options)).to eq("SomeKey")
|
47
47
|
end
|
48
48
|
|
49
49
|
it "when except is defined, dont convert this key" do
|
50
|
-
options = {key_converter: :camelcase, except: "some_key"}
|
50
|
+
options = { key_converter: :camelcase, except: "some_key" }
|
51
51
|
expect(create(:some_key, options)).to eq("someKey")
|
52
52
|
end
|
53
53
|
end
|
@@ -46,7 +46,7 @@ describe Gyoku::XMLValue do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "hash objects get converted to xml" do
|
49
|
-
object = {document!: {"@version" => "2.0", :content! => {key!: "value", other_key: {"@attribute" => "value", :content! => {key: "value"}}}}}
|
49
|
+
object = { document!: { "@version" => "2.0", :content! => { key!: "value", other_key: { "@attribute" => "value", :content! => { key: "value" } } } } }
|
50
50
|
expect(create(object)).to eq("<document version=\"2.0\"><key>value</key><otherKey attribute=\"value\"><key>value</key></otherKey></document>")
|
51
51
|
end
|
52
52
|
|
@@ -25,31 +25,31 @@ describe Gyoku do
|
|
25
25
|
|
26
26
|
describe ".xml" do
|
27
27
|
it "translates a given Hash to XML" do
|
28
|
-
hash = {id: 1}
|
28
|
+
hash = { id: 1 }
|
29
29
|
xml = Gyoku.xml(hash, element_form_default: :qualified)
|
30
30
|
|
31
31
|
expect(xml).to eq("<id>1</id>")
|
32
32
|
end
|
33
33
|
|
34
34
|
it "accepts a key_converter for the Hash keys" do
|
35
|
-
hash = {user_name: "finn", pass_word: "secret"}
|
36
|
-
xml = Gyoku.xml(hash, {key_converter: :upcase})
|
35
|
+
hash = { user_name: "finn", pass_word: "secret" }
|
36
|
+
xml = Gyoku.xml(hash, { key_converter: :upcase })
|
37
37
|
|
38
38
|
expect(xml).to include("<USER_NAME>finn</USER_NAME>")
|
39
39
|
expect(xml).to include("<PASS_WORD>secret</PASS_WORD>")
|
40
40
|
end
|
41
41
|
|
42
42
|
it "don't converts Strings keys" do
|
43
|
-
hash = {:user_name => "finn", "pass_word" => "secret"}
|
44
|
-
xml = Gyoku.xml(hash, {key_converter: :upcase})
|
43
|
+
hash = { :user_name => "finn", "pass_word" => "secret" }
|
44
|
+
xml = Gyoku.xml(hash, { key_converter: :upcase })
|
45
45
|
|
46
46
|
expect(xml).to include("<USER_NAME>finn</USER_NAME>")
|
47
47
|
expect(xml).to include("<pass_word>secret</pass_word>")
|
48
48
|
end
|
49
49
|
|
50
50
|
it "when defined key_to_convert only convert this key" do
|
51
|
-
hash = {user_name: "finn", pass_word: "secret"}
|
52
|
-
options = {key_converter: :upcase, key_to_convert: "user_name"}
|
51
|
+
hash = { user_name: "finn", pass_word: "secret" }
|
52
|
+
options = { key_converter: :upcase, key_to_convert: "user_name" }
|
53
53
|
xml = Gyoku.xml(hash, options)
|
54
54
|
|
55
55
|
expect(xml).to include("<USER_NAME>finn</USER_NAME>")
|
@@ -57,8 +57,8 @@ describe Gyoku do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it "accepts key_converter for nested hash" do
|
60
|
-
hash = {user: {user_name: "finn", pass_word: "secret"}}
|
61
|
-
xml = Gyoku.xml(hash, {key_converter: :upcase})
|
60
|
+
hash = { user: { user_name: "finn", pass_word: "secret" } }
|
61
|
+
xml = Gyoku.xml(hash, { key_converter: :upcase })
|
62
62
|
|
63
63
|
expect(xml).to include("<USER><USER_NAME>finn</USER_NAME>")
|
64
64
|
expect(xml).to include("<PASS_WORD>secret</PASS_WORD></USER>")
|
@@ -69,9 +69,9 @@ describe Gyoku do
|
|
69
69
|
person: {
|
70
70
|
first_name: "Lucy",
|
71
71
|
last_name: "Sky",
|
72
|
-
order!:
|
72
|
+
order!: %i{first_name last_name},
|
73
73
|
},
|
74
|
-
attributes!: {person: {id: "666"}}
|
74
|
+
attributes!: { person: { id: "666" } },
|
75
75
|
}
|
76
76
|
original_hash = hash.dup
|
77
77
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-gyoku
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Harrington
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: builder
|
@@ -29,14 +29,14 @@ dependencies:
|
|
29
29
|
requirements:
|
30
30
|
- - "~>"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '3.
|
32
|
+
version: '3.4'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '3.
|
39
|
+
version: '3.4'
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: rake
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,34 +79,65 @@ dependencies:
|
|
79
79
|
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '0'
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: fiddle
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: cookstyle
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 8.0.0
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 8.0.0
|
82
110
|
description: Gyoku translates Ruby Hashes to XML
|
83
111
|
email: me@rubiii.com
|
84
112
|
executables: []
|
85
113
|
extensions: []
|
86
114
|
extra_rdoc_files: []
|
87
115
|
files:
|
116
|
+
- ".github/dependabot.yml"
|
88
117
|
- ".github/workflows/ci.yml"
|
118
|
+
- ".github/workflows/lint.yml"
|
89
119
|
- ".gitignore"
|
90
120
|
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
91
122
|
- CHANGELOG.md
|
92
123
|
- Gemfile
|
93
124
|
- MIT-LICENSE
|
94
125
|
- README.md
|
95
126
|
- Rakefile
|
96
|
-
- gyoku.gemspec
|
97
|
-
- lib/gyoku.rb
|
98
|
-
- lib/gyoku/array.rb
|
99
|
-
- lib/gyoku/hash.rb
|
100
|
-
- lib/gyoku/prettifier.rb
|
101
|
-
- lib/gyoku/version.rb
|
102
|
-
- lib/gyoku/xml_key.rb
|
103
|
-
- lib/gyoku/xml_value.rb
|
104
|
-
- spec/gyoku/array_spec.rb
|
105
|
-
- spec/gyoku/hash_spec.rb
|
106
|
-
- spec/gyoku/prettifier_spec.rb
|
107
|
-
- spec/gyoku/xml_key_spec.rb
|
108
|
-
- spec/gyoku/xml_value_spec.rb
|
109
|
-
- spec/gyoku_spec.rb
|
127
|
+
- chef-gyoku.gemspec
|
128
|
+
- lib/chef-gyoku.rb
|
129
|
+
- lib/chef-gyoku/array.rb
|
130
|
+
- lib/chef-gyoku/hash.rb
|
131
|
+
- lib/chef-gyoku/prettifier.rb
|
132
|
+
- lib/chef-gyoku/version.rb
|
133
|
+
- lib/chef-gyoku/xml_key.rb
|
134
|
+
- lib/chef-gyoku/xml_value.rb
|
135
|
+
- spec/chef-gyoku/array_spec.rb
|
136
|
+
- spec/chef-gyoku/hash_spec.rb
|
137
|
+
- spec/chef-gyoku/prettifier_spec.rb
|
138
|
+
- spec/chef-gyoku/xml_key_spec.rb
|
139
|
+
- spec/chef-gyoku/xml_value_spec.rb
|
140
|
+
- spec/chef-gyoku_spec.rb
|
110
141
|
- spec/spec_helper.rb
|
111
142
|
homepage: https://github.com/savonrb/chef-gyoku
|
112
143
|
licenses:
|
@@ -119,14 +150,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
150
|
requirements:
|
120
151
|
- - ">="
|
121
152
|
- !ruby/object:Gem::Version
|
122
|
-
version: '3.
|
153
|
+
version: '3.1'
|
123
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
155
|
requirements:
|
125
156
|
- - ">="
|
126
157
|
- !ruby/object:Gem::Version
|
127
158
|
version: '0'
|
128
159
|
requirements: []
|
129
|
-
rubygems_version: 3.6.
|
160
|
+
rubygems_version: 3.6.8
|
130
161
|
specification_version: 4
|
131
162
|
summary: Translates Ruby Hashes to XML
|
132
163
|
test_files: []
|
data/lib/gyoku/version.rb
DELETED