cfa 1.0.0 → 1.0.1

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: 4a1b7d04b80d8f3847c52a299c581eb93ce99504aa21df9ff777766fbdd9a693
4
- data.tar.gz: eb11d86a2949be4b60227c4e6a2d834ad8c8fa9f142db99bbd4b011827cc27aa
3
+ metadata.gz: fd707324d0e3ad8265613743072f4557a1907be8c4db9074e323134eaa7acfe6
4
+ data.tar.gz: 0a7fc0fb5020ce4edbad0f47f6124b28904fdd039f8ccf0382e7781688f35a50
5
5
  SHA512:
6
- metadata.gz: 0f6e65715be7e500b23ab82c025082c97c035af9ca878f76543fa571b3a22ea3feda7dc535fd974704d5e6b2a13465723068fa066dcd7eef75a1e28b9023d4bf
7
- data.tar.gz: c4e7641eb00264924223db6491e09a80f4acb1c987074c579e63e78b22eae6caa94fe57319ba28d9fe4b4fea5a703f097579ce9a413641fc29c52decc364f09e
6
+ metadata.gz: b5b04935b9112cad8cbe806d6a23d3933d27c1ee2a6c0d198e92a30a72e493d9034883424e1e46301b740eea7e49f6324ec3d7c760ca0cc58c1f13e487d9e53b
7
+ data.tar.gz: 42c7343d2933ad4ef95d363ccbaf55d9d366d35ef98eb7cc0dfc4d506b52f2cc0044f085afd0bb9754c9653f47fde430eeb332e23e8f66b84410a09819f02bad
@@ -301,12 +301,35 @@ module CFA
301
301
  # @param preceding [LocatedEntry]
302
302
  def path_after(preceding)
303
303
  paths = aug.match(preceding.prefix + "/*")
304
- preceding_index = paths.index(preceding.path)
305
- # it can happen, that insertion change previous entry from
306
- # e.g. #comment to #comment[1]. Can happen only if it switch from
307
- # single entry to collection
308
- preceding_index ||= paths.index(preceding.path + "[1]")
309
- paths[preceding_index + 1]
304
+ paths[find_preceding_index(paths, preceding) + 1]
305
+ end
306
+
307
+ def find_preceding_index(paths, preceding)
308
+ path = preceding.path
309
+ # common case, just included
310
+ return paths.index(path) if paths.include?(path)
311
+
312
+ # not found, so it means that some collection or single entry switch
313
+ new_path = +"/"
314
+ path.split("/").each do |element|
315
+ new_path << "/" unless new_path.end_with?("/")
316
+ new_path << pick_candidate(paths, new_path, element)
317
+ end
318
+
319
+ paths.index(new_path) ||
320
+ raise("Cannot find path #{preceding.path} in #{paths.inspect}")
321
+ end
322
+
323
+ # it returns variant of element that exists in path
324
+ def pick_candidate(paths, new_path, element)
325
+ # NOTE: order here is important due to early matching
326
+ candidates = [element + "/", element + "[1]",
327
+ element.sub(/\[\d+\]/, ""), element]
328
+ paths.each do |p|
329
+ candidates.each do |c|
330
+ return c if p.start_with?(new_path + c)
331
+ end
332
+ end
310
333
  end
311
334
  end
312
335
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josef Reidinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-21 00:00:00.000000000 Z
11
+ date: 2019-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-augeas