patchyaml 0.1.1 → 0.1.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/lib/patchyaml/editor.rb +10 -0
- data/lib/patchyaml/find.rb +4 -2
- data/lib/patchyaml/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: '09030d2cd8460fc135a5b74cc74277933efb7b9ba90c2cfa59fe14ea5de7496e'
|
|
4
|
+
data.tar.gz: 2ba8dddffcd1aa85adcaf10ae2aa92583a7ab10b61eb6c09be6771b9947adb33
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7e4d2de2e5ea6b51a40788003ca8284a5c73a025ddcc12c5f4cecb59359809ed055423e119fa2f7e16651ecdd93936feeca3cc1552b1db9a800f9965d7e31508
|
|
7
|
+
data.tar.gz: 0603fc03c1bbc826ddd80ec3f04d9cbf1d9a75ab065ce62e0485ad307add6146cf8ac9ef82430933aad3f02d02516343f6fb1cba33884fced9e447f98bf99b6a
|
data/lib/patchyaml/editor.rb
CHANGED
|
@@ -9,6 +9,16 @@ module PatchYAML
|
|
|
9
9
|
reload(data)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
# Determines whether a given path exists in the loaded YAML
|
|
13
|
+
#
|
|
14
|
+
# path - Path to be checked
|
|
15
|
+
#
|
|
16
|
+
# Returns true if the path exists, false otherwise.
|
|
17
|
+
def exist?(path)
|
|
18
|
+
value, parent = find(@stream, path)
|
|
19
|
+
!value.nil?
|
|
20
|
+
end
|
|
21
|
+
|
|
12
22
|
# Deletes a given path from the yaml
|
|
13
23
|
#
|
|
14
24
|
# path - The path to the key to be deleted
|
data/lib/patchyaml/find.rb
CHANGED
|
@@ -8,7 +8,7 @@ module PatchYAML
|
|
|
8
8
|
node = [from, nil]
|
|
9
9
|
path.each do |part|
|
|
10
10
|
node = find_node(node, part)
|
|
11
|
-
return [] if node.empty?
|
|
11
|
+
return [] if node.nil? || node.empty?
|
|
12
12
|
end
|
|
13
13
|
node
|
|
14
14
|
end
|
|
@@ -28,6 +28,8 @@ module PatchYAML
|
|
|
28
28
|
raise "patchyaml: Unknown anchor #{from.anchor} defined by #{from.first}" unless node
|
|
29
29
|
|
|
30
30
|
[find_node(node, part), node]
|
|
31
|
+
when NilClass
|
|
32
|
+
return []
|
|
31
33
|
else
|
|
32
34
|
raise "patchyaml: Unexpected node #{from.first.class} in #find_node"
|
|
33
35
|
end
|
|
@@ -46,7 +48,7 @@ module PatchYAML
|
|
|
46
48
|
v = from
|
|
47
49
|
.first
|
|
48
50
|
.children
|
|
49
|
-
.find { it.is_a?(Psych::Nodes::Mapping) && find_mapping_key(it, part[:key]).value == part[:value] }
|
|
51
|
+
.find { it.is_a?(Psych::Nodes::Mapping) && find_mapping_key(it, part[:key]).first.value == part[:value] }
|
|
50
52
|
[v, from]
|
|
51
53
|
end
|
|
52
54
|
end
|
data/lib/patchyaml/version.rb
CHANGED