patchyaml 0.1.1 → 0.1.3
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/pipeline.rb +6 -1
- data/lib/patchyaml/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 55842aa3173a34dd262ddd288264ca567e7f1952ff48b45173b995de12dddd9f
|
|
4
|
+
data.tar.gz: d08a821c86738f7f444bbf98ed9dc04bb2cdb915c03a6da46173b73d14929baa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 70f569d41f4117778542b37cd4bb19012cee815b43e6997e011c73738ef68b038f6436595bc7eb0ad04b5a188b1ad51180ad6f1e9b2b9dae8612bbd9471c56e2
|
|
7
|
+
data.tar.gz: 38645753c1638a167ed83960b1f8a59bde245ef07c785378a990cc4cf4d1d2c08cb8f697aa561ae8800de544937bc67b847a7f0958c28234a558cfe87971c1c7
|
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/pipeline.rb
CHANGED
|
@@ -111,10 +111,15 @@ module PatchYAML
|
|
|
111
111
|
key = parent.children[key_index]
|
|
112
112
|
start_at = start_offset(value)
|
|
113
113
|
end_at = end_offset(value)
|
|
114
|
+
end_at -= 1 if @data[end_at - 1] == "\n"
|
|
114
115
|
yaml_value = dump_yaml(new_value, indent: key.start_column + 2)
|
|
115
|
-
indent =
|
|
116
|
+
indent = case
|
|
117
|
+
when new_value.is_a?(Hash)
|
|
116
118
|
start_at -= 1 while @data[start_at - 1] == " "
|
|
117
119
|
"\n#{" " * (key.start_column + 2)}"
|
|
120
|
+
when (new_value.is_a?(Array) && parent.style != Psych::Nodes::Mapping::FLOW)
|
|
121
|
+
start_at -= 1 while @data[start_at - 1] == " "
|
|
122
|
+
"#{" " * (key.start_column + 2)}"
|
|
118
123
|
else
|
|
119
124
|
""
|
|
120
125
|
end
|
data/lib/patchyaml/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: patchyaml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vito Sartori
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 2025-10-27 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: YAML Editor Utility Library
|
|
13
13
|
email:
|
|
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
51
51
|
- !ruby/object:Gem::Version
|
|
52
52
|
version: '0'
|
|
53
53
|
requirements: []
|
|
54
|
-
rubygems_version: 3.6.
|
|
54
|
+
rubygems_version: 3.6.2
|
|
55
55
|
specification_version: 4
|
|
56
56
|
summary: YAML Editor Utility Library
|
|
57
57
|
test_files: []
|