eac_config 0.11.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eac_config/entries.rb +35 -0
- data/lib/eac_config/entry/not_found_error.rb +13 -0
- data/lib/eac_config/entry.rb +7 -0
- data/lib/eac_config/entry_path.rb +27 -0
- data/lib/eac_config/envvars_node.rb +6 -0
- data/lib/eac_config/node.rb +7 -1
- data/lib/eac_config/node_entry.rb +1 -0
- data/lib/eac_config/version.rb +1 -1
- data/lib/eac_config/yaml_file_node/self_entries.rb +72 -0
- data/lib/eac_config/yaml_file_node.rb +3 -0
- metadata +13 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a6f32e20faefd54b3f85d008539d97fd3298cd6fe8b1118f321a8bdd3f0e9c9
|
4
|
+
data.tar.gz: 75d5c1c5691aacfec07532f102011119bf41e9991997d1a2c86cb201a271894a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/eac_config/entry.rb
CHANGED
@@ -5,6 +5,7 @@ require 'eac_ruby_utils/core_ext'
|
|
5
5
|
|
6
6
|
module EacConfig
|
7
7
|
class Entry
|
8
|
+
require_sub __FILE__
|
8
9
|
enable_simple_cache
|
9
10
|
common_constructor :root_node, :path do
|
10
11
|
self.path = ::EacConfig::EntryPath.assert(path)
|
@@ -30,6 +31,12 @@ module EacConfig
|
|
30
31
|
node_entry.if_present(&:value)
|
31
32
|
end
|
32
33
|
|
34
|
+
def value!
|
35
|
+
return value if found?
|
36
|
+
|
37
|
+
raise ::EacConfig::Entry::NotFoundError, self
|
38
|
+
end
|
39
|
+
|
33
40
|
def value=(a_value)
|
34
41
|
write_node.self_entry(path).value = a_value
|
35
42
|
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
|
data/lib/eac_config/node.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/eac_config/version.rb
CHANGED
@@ -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.
|
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:
|
11
|
+
date: 2023-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.8'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.8.4
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,20 +27,23 @@ dependencies:
|
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '2.8'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.8.4
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: eac_ruby_utils
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
39
|
+
version: '0.119'
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
46
|
+
version: '0.119'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: eac_ruby_gem_support
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,7 +65,9 @@ extensions: []
|
|
59
65
|
extra_rdoc_files: []
|
60
66
|
files:
|
61
67
|
- lib/eac_config.rb
|
68
|
+
- lib/eac_config/entries.rb
|
62
69
|
- lib/eac_config/entry.rb
|
70
|
+
- lib/eac_config/entry/not_found_error.rb
|
63
71
|
- lib/eac_config/entry_path.rb
|
64
72
|
- lib/eac_config/envvars_node.rb
|
65
73
|
- lib/eac_config/envvars_node/entry.rb
|
@@ -82,6 +90,7 @@ files:
|
|
82
90
|
- lib/eac_config/version.rb
|
83
91
|
- lib/eac_config/yaml_file_node.rb
|
84
92
|
- lib/eac_config/yaml_file_node/entry.rb
|
93
|
+
- lib/eac_config/yaml_file_node/self_entries.rb
|
85
94
|
homepage:
|
86
95
|
licenses: []
|
87
96
|
metadata: {}
|