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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9e38cd938e2c0d06f487f5eae3ef6cf9e21b08126488c5a09d576bd98ead334
4
- data.tar.gz: eb53162c6795adafdd7005c8e8ba320185e82a3cd0e22b8eba245f667755c3ba
3
+ metadata.gz: 55842aa3173a34dd262ddd288264ca567e7f1952ff48b45173b995de12dddd9f
4
+ data.tar.gz: d08a821c86738f7f444bbf98ed9dc04bb2cdb915c03a6da46173b73d14929baa
5
5
  SHA512:
6
- metadata.gz: beb5ddac331f2d2c6a4ca22ae06f8ee3619c5504ff4a24ba5f3825d07dc83a64528925a367b24eefe45bc40a8b51ab6080637b8afd938af977b2074b6bd71c81
7
- data.tar.gz: beda8aebf99145a8d1b44b872d4d72e9b1bda238d6ee07ab6e089b9e07d7904a111f5fc638d1a1ffce30242bb06bd26e6d3c5def5fcc78fcd5d1c2766ed0e8c9
6
+ metadata.gz: 70f569d41f4117778542b37cd4bb19012cee815b43e6997e011c73738ef68b038f6436595bc7eb0ad04b5a188b1ad51180ad6f1e9b2b9dae8612bbd9471c56e2
7
+ data.tar.gz: 38645753c1638a167ed83960b1f8a59bde245ef07c785378a990cc4cf4d1d2c08cb8f697aa561ae8800de544937bc67b847a7f0958c28234a558cfe87971c1c7
@@ -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
@@ -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
@@ -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 = if new_value.is_a?(Hash) || (new_value.is_a?(Array) && parent.style != Psych::Nodes::Mapping::FLOW)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Patchyaml
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
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.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: 1980-01-02 00:00:00.000000000 Z
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.7
54
+ rubygems_version: 3.6.2
55
55
  specification_version: 4
56
56
  summary: YAML Editor Utility Library
57
57
  test_files: []