to_simple_yaml 1.0.9 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/to_simple_yaml/core.rb +7 -3
- data/lib/to_simple_yaml/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c8b25ea6a6795b751c6e0e76e01d969ae6a9a7843ac142072f31800932694ab
|
4
|
+
data.tar.gz: 80bf8a37f9d0b8498350d1764ca849e171b1791dba5eaa4de2a96a071a452ab3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21a2473079aa1795e7c582d09adf2b068779981f636d6498149b7aefce91ce1bd152c685f3dc7fa655d667df8708983b253213d6eb2c6cd9eabb81a31cc2da23
|
7
|
+
data.tar.gz: b43b5ae0ac0254cd4389c13c03d79590284fdc8c3556597006ebcac1c025e14a4290e36d5f1b27a25c5fd66edf49009d6032bbdd3a60a88c45344d83780becbb
|
data/Gemfile.lock
CHANGED
data/lib/to_simple_yaml/core.rb
CHANGED
@@ -21,7 +21,7 @@ class Object
|
|
21
21
|
|
22
22
|
def generate_yaml(obj, indent: 0, array: false)
|
23
23
|
if obj.is_a?(Hash)
|
24
|
-
return template("#{array ? '- ' : ''}{}", indent) if obj.
|
24
|
+
return template("#{array ? '- ' : ''}{}", indent) if obj.empty?
|
25
25
|
|
26
26
|
yaml = ''
|
27
27
|
obj.compact.keys.each_with_index do |key, index|
|
@@ -38,8 +38,12 @@ class Object
|
|
38
38
|
elsif obj[key].is_a?(String) || obj[key].is_a?(Symbol) || obj[key].is_a?(Numeric) || obj[key].is_a?(TrueClass) || obj[key].is_a?(FalseClass)
|
39
39
|
yaml << template("#{array_first ? '- ' : ''}#{text(key)}: #{text(obj[key])}", array_inline ? indent + 1 : indent)
|
40
40
|
elsif obj[key].is_a?(Array)
|
41
|
-
|
42
|
-
|
41
|
+
if obj[key].empty?
|
42
|
+
yaml << template("#{array_first ? '- ' : ''}#{text(key)}: []", array_inline ? indent + 1 : indent)
|
43
|
+
else
|
44
|
+
yaml << template("#{array_first ? '- ' : ''}#{text(key)}:", array_inline ? indent + 1 : indent)
|
45
|
+
yaml << generate_yaml(obj[key], indent: array_inline ? indent + 2 : indent + 1)
|
46
|
+
end
|
43
47
|
else
|
44
48
|
yaml << template("#{array_first ? '- ' : ''}#{text(key)}:", array_inline ? indent + 1 : indent)
|
45
49
|
yaml << generate_yaml(obj[key], indent: array_inline || array_first ? indent + 2 : indent + 1)
|