patchyaml 0.1.3 → 0.1.4
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 +2 -2
- data/lib/patchyaml/find.rb +1 -1
- data/lib/patchyaml/pipeline.rb +35 -6
- data/lib/patchyaml/version.rb +2 -2
- 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: 27d24b69a097c75a45afb302b0b4199b9bc2ed45bd34d8cf141717def23e6f03
|
|
4
|
+
data.tar.gz: ec42ec73c55a184ee211cc1b9fbc3f907380d85fa2b5fc951bdaeb2abde66e69
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 579bec7e6859c1befd69cebcbf7e67d1ab7c4352bfd377160838fbd89d22d98602d251e64772d26d1428fa9e801202cd881ed7e2d35625b5e499a7498328c3f2
|
|
7
|
+
data.tar.gz: c0e4cdc1e179f6832663a102585e838a79f7083f8c7f1abad058685214ef5af8c2b3f1531acaf40543aeb8cdf6fe3fa77b856e0b1a957f087aafdc3ad44ea700
|
data/lib/patchyaml/editor.rb
CHANGED
|
@@ -15,7 +15,7 @@ module PatchYAML
|
|
|
15
15
|
#
|
|
16
16
|
# Returns true if the path exists, false otherwise.
|
|
17
17
|
def exist?(path)
|
|
18
|
-
value,
|
|
18
|
+
value, = find(@stream, path)
|
|
19
19
|
!value.nil?
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -73,7 +73,7 @@ module PatchYAML
|
|
|
73
73
|
private
|
|
74
74
|
|
|
75
75
|
def reload(data)
|
|
76
|
-
@data = data
|
|
76
|
+
@data = data.end_with?("\n") ? data : data.concat("\n")
|
|
77
77
|
@line_sizes = [0] + data.split("\n").map { it.length + 1 }
|
|
78
78
|
begin
|
|
79
79
|
@stream = Psych.parse_stream(data)
|
data/lib/patchyaml/find.rb
CHANGED
data/lib/patchyaml/pipeline.rb
CHANGED
|
@@ -104,6 +104,22 @@ module PatchYAML
|
|
|
104
104
|
end
|
|
105
105
|
end
|
|
106
106
|
|
|
107
|
+
def detect_stripped_whitespace(from)
|
|
108
|
+
stripped = []
|
|
109
|
+
loop do
|
|
110
|
+
case @data[from]
|
|
111
|
+
when " ", "\t"
|
|
112
|
+
stripped << @data[from]
|
|
113
|
+
from -= 1
|
|
114
|
+
when "\n"
|
|
115
|
+
stripped << "\n"
|
|
116
|
+
return stripped.reverse.join
|
|
117
|
+
else
|
|
118
|
+
return ""
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
107
123
|
# TODO: update_* does not take into consideration adding a complex, multiline
|
|
108
124
|
# value into an inline parent. This will certainly break things.
|
|
109
125
|
def update_mapping(value, parent, new_value)
|
|
@@ -111,21 +127,34 @@ module PatchYAML
|
|
|
111
127
|
key = parent.children[key_index]
|
|
112
128
|
start_at = start_offset(value)
|
|
113
129
|
end_at = end_offset(value)
|
|
114
|
-
end_at -= 1 if @data[end_at - 1] == "\n"
|
|
115
130
|
yaml_value = dump_yaml(new_value, indent: key.start_column + 2)
|
|
131
|
+
start_at -= 1 while @data[start_at - 1] == " "
|
|
132
|
+
|
|
133
|
+
# Psych assumes trailing whitespaces belong to the current value,
|
|
134
|
+
# which may cause newlines to be stripped when replacing a whole
|
|
135
|
+
# block. Here we detect how much was removed, so we can re-add it
|
|
136
|
+
# later when reassembling the file.
|
|
137
|
+
stripped = detect_stripped_whitespace(end_at - 1)
|
|
138
|
+
|
|
139
|
+
# rubocop:disable Lint/DuplicateBranch
|
|
116
140
|
indent = case
|
|
117
141
|
when new_value.is_a?(Hash)
|
|
118
|
-
start_at -= 1 while @data[start_at - 1] == " "
|
|
119
142
|
"\n#{" " * (key.start_column + 2)}"
|
|
120
|
-
when
|
|
121
|
-
|
|
122
|
-
|
|
143
|
+
when new_value.is_a?(Array) && value.style == Psych::Nodes::Sequence::FLOW && value.children.empty?
|
|
144
|
+
"\n#{" " * (key.start_column + 2)}"
|
|
145
|
+
when new_value.is_a?(Array) && parent.style != Psych::Nodes::Mapping::FLOW
|
|
146
|
+
(" " * (key.start_column + 2)).to_s
|
|
147
|
+
when new_value.is_a?(String)
|
|
148
|
+
" "
|
|
123
149
|
else
|
|
124
|
-
""
|
|
150
|
+
(" " * (key.start_column + 2)).to_s
|
|
125
151
|
end
|
|
152
|
+
# rubocop:enable Lint/DuplicateBranch
|
|
153
|
+
|
|
126
154
|
@data = @data[...start_at]
|
|
127
155
|
.concat(indent)
|
|
128
156
|
.concat(yaml_value)
|
|
157
|
+
.concat(stripped)
|
|
129
158
|
.concat(@data[end_at...])
|
|
130
159
|
end
|
|
131
160
|
|
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.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vito Sartori
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 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.7
|
|
55
55
|
specification_version: 4
|
|
56
56
|
summary: YAML Editor Utility Library
|
|
57
57
|
test_files: []
|