eac_config 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5039f8ba469fc8a37d89548e84cee3fcbcd20962dc71d0c64f0709168801d158
4
- data.tar.gz: 5724d1a93450a3f7f7f3b71ca5f227febbd6cc23bf20279cb048f4df847d5389
3
+ metadata.gz: 6a6f32e20faefd54b3f85d008539d97fd3298cd6fe8b1118f321a8bdd3f0e9c9
4
+ data.tar.gz: 75d5c1c5691aacfec07532f102011119bf41e9991997d1a2c86cb201a271894a
5
5
  SHA512:
6
- metadata.gz: e753cb72711c058b4d2165e7383c3990b0ed80d2c00c07535a0753d7628bc2128c00bd37733dbb7175a0cb7752f3d0044ca32af3ab87e7ce5c329d6d24f02aad
7
- data.tar.gz: 8410beb66cdd45f591f3d7054b9785e8de0e21c2e467c7bb79415f7c2713a8d95ac1755ed9c0e91f0e7b65fc13a98e805360fb948314e5d5be54474e1a89a611
6
+ metadata.gz: 144d2b6323592b447ef0b89a24845789ec88153c244209a723fa7aa62b3005bb7c8d8d2b5ad34b4f7f539c33cfcc3c06c9f2230ab6e8aa10b8b28bdb75cf347d
7
+ data.tar.gz: 3e807e994d32698e4a5ab8ea74a44846cfad0bf71923e15a534d8ae1eeaf2d4c9876fb498c317d12b16496190fe07aae87f8968c0521d352a2bdf3a71629c3e8
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_config/entry_path'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EacConfig
7
+ class Entries
8
+ require_sub __FILE__
9
+ enable_simple_cache
10
+ common_constructor :root_node, :path do
11
+ self.path = ::EacConfig::EntryPath.assert(path)
12
+ end
13
+
14
+ def to_s
15
+ "#{self.class}[RootNode: #{root_node}, Path: #{path}]"
16
+ end
17
+
18
+ private
19
+
20
+ # @return [Array<EacConfig::Entries>]
21
+ def node_entries_uncached
22
+ node_entries_from_root + node_entries_from_load_path
23
+ end
24
+
25
+ # @return [Array<EacConfig::Entries>]
26
+ def node_entries_from_load_path_uncached
27
+ root_node.recursive_loaded_nodes.flat_map { |loaded_node| loaded_node.self_entries(path) }
28
+ end
29
+
30
+ # @return [Array<EacConfig::Entries>]
31
+ def node_entries_from_root_uncached
32
+ root_node.self_entries(path)
33
+ end
34
+ end
35
+ end
@@ -58,5 +58,32 @@ module EacConfig
58
58
  def to_string
59
59
  parts.join(PART_SEPARATOR)
60
60
  end
61
+
62
+ # @param part [String]
63
+ # @return [EacConfig::EntryPath]
64
+ def with_first(part)
65
+ new_parts = parts.dup
66
+ new_parts.unshift(part)
67
+ self.class.new(new_parts)
68
+ end
69
+
70
+ # @return [EacConfig::EntryPath]
71
+ def without_first
72
+ new_parts = parts.dup
73
+ new_parts.shift
74
+ self.class.new(new_parts)
75
+ end
76
+
77
+ # @return [EacConfig::EntryPath]
78
+ def with_last(part)
79
+ self.class.new(parts + [part])
80
+ end
81
+
82
+ # @return [EacConfig::EntryPath]
83
+ def without_last
84
+ new_parts = parts.dup
85
+ new_parts.pop
86
+ self.class.new(new_parts)
87
+ end
61
88
  end
62
89
  end
@@ -18,6 +18,12 @@ module EacConfig
18
18
  end
19
19
  end
20
20
 
21
+ # @param path [EacConfig::EntryPath]
22
+ # @return [Array<EacConfig::Entries>]
23
+ def self_entries(_path)
24
+ []
25
+ end
26
+
21
27
  def url
22
28
  URI
23
29
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_config/entries'
3
4
  require 'eac_config/entry'
4
5
  require 'eac_config/entry_path'
5
6
  require 'eac_config/load_path'
@@ -20,10 +21,15 @@ module EacConfig
20
21
  attr_accessor :write_node
21
22
 
22
23
  common_concern do
23
- enable_abstract_methods
24
+ acts_as_abstract :self_entries
24
25
  include ::Comparable
25
26
  end
26
27
 
28
+ # @return [Array<EacConfig::Entries>]
29
+ def entries(path)
30
+ ::EacConfig::Entries.new(self, path)
31
+ end
32
+
27
33
  def entry(path)
28
34
  ::EacConfig::Entry.new(self, path)
29
35
  end
@@ -12,6 +12,7 @@ module EacConfig
12
12
  common_constructor :node, :path do
13
13
  self.path = ::EacConfig::EntryPath.assert(path)
14
14
  end
15
+ compare_by :node, :path
15
16
 
16
17
  abstract_methods :found?, :value, :value=
17
18
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacConfig
4
- VERSION = '0.12.0'
4
+ VERSION = '0.13.0'
5
5
  end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_config/entry_path'
4
+ require 'eac_config/yaml_file_node/entry'
5
+ require 'eac_ruby_utils/core_ext'
6
+ require 'eac_ruby_utils/wildcards'
7
+
8
+ module EacConfig
9
+ class YamlFileNode
10
+ class SelfEntries
11
+ acts_as_instance_method
12
+ common_constructor :node, :path do
13
+ self.path = ::EacConfig::EntryPath.assert(path)
14
+ end
15
+
16
+ # @return [Array<EacConfig::YamlFileNode>]
17
+ def result
18
+ head_node.result.map { |found_path| ::EacConfig::YamlFileNode::Entry.new(node, found_path) }
19
+ end
20
+
21
+ private
22
+
23
+ # @return [DataNode]
24
+ def head_node
25
+ DataNode.new(node.data, ::EacConfig::EntryPath.new, path)
26
+ end
27
+
28
+ class DataNode
29
+ common_constructor :data_node, :path_from, :path_to do
30
+ self.data_node = data_node.stringify_keys if data_node.is_a?(::Hash)
31
+ end
32
+
33
+ # @return [DataNode]
34
+ def child(child_key)
35
+ self.class.new(data_node.fetch(child_key), path_from.with_last(child_key),
36
+ path_to.without_first)
37
+ end
38
+
39
+ def children
40
+ return [] unless data_node.is_a?(::Hash)
41
+
42
+ data_node.keys.select { |k| key_matcher.match?(k) }.map { |k| child(k) }
43
+ end
44
+
45
+ # @return [Symbol]
46
+ def key
47
+ path_to.first
48
+ end
49
+
50
+ # @return [EacRubyUtils::Wildcards]
51
+ def key_matcher
52
+ @key_matcher ||= ::EacRubyUtils::Wildcards.new(key)
53
+ end
54
+
55
+ # @return [Array<EacConfig::EntryPath>]
56
+ def result
57
+ (path_to.empty? ? result_from_self : result_from_children)
58
+ end
59
+
60
+ # @return [Array<EacConfig::EntryPath>]
61
+ def result_from_self
62
+ [path_from]
63
+ end
64
+
65
+ # @return [Array<EacConfig::EntryPath>]
66
+ def result_from_children
67
+ children.flat_map(&:result)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -20,6 +20,7 @@ module EacConfig
20
20
  common_constructor :path do
21
21
  self.path = path.to_pathname
22
22
  end
23
+ compare_by :path
23
24
 
24
25
  def persist_data(new_data)
25
26
  path.parent.mkpath
@@ -47,5 +48,7 @@ module EacConfig
47
48
 
48
49
  r.is_a?(::Hash) ? r : {}
49
50
  end
51
+
52
+ require_sub __FILE__, require_mode: :kernel
50
53
  end
51
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-02 00:00:00.000000000 Z
11
+ date: 2023-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '2.8'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 2.8.1
22
+ version: 2.8.4
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,21 +29,21 @@ dependencies:
29
29
  version: '2.8'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 2.8.1
32
+ version: 2.8.4
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: eac_ruby_utils
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0.107'
39
+ version: '0.119'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0.107'
46
+ version: '0.119'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: eac_ruby_gem_support
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -65,6 +65,7 @@ extensions: []
65
65
  extra_rdoc_files: []
66
66
  files:
67
67
  - lib/eac_config.rb
68
+ - lib/eac_config/entries.rb
68
69
  - lib/eac_config/entry.rb
69
70
  - lib/eac_config/entry/not_found_error.rb
70
71
  - lib/eac_config/entry_path.rb
@@ -89,6 +90,7 @@ files:
89
90
  - lib/eac_config/version.rb
90
91
  - lib/eac_config/yaml_file_node.rb
91
92
  - lib/eac_config/yaml_file_node/entry.rb
93
+ - lib/eac_config/yaml_file_node/self_entries.rb
92
94
  homepage:
93
95
  licenses: []
94
96
  metadata: {}