eac_config 0.1.0 → 0.2.0
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/eac_config/entry_path.rb +6 -2
- data/lib/eac_config/entry_search.rb +15 -5
- data/lib/eac_config/load_nodes_search.rb +39 -0
- data/lib/eac_config/node.rb +45 -0
- data/lib/eac_config/version.rb +1 -1
- data/lib/eac_config/yaml_file_node.rb +5 -6
- metadata +18 -5
- data/lib/eac_config/manager.rb +0 -14
- data/lib/eac_config/readable_node.rb +0 -6
- data/lib/eac_config/writeable_node.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd6a6d3c5ab71a03c476e9d3237623e6d9911128c27301c73dcaf3fdc3e49e33
|
4
|
+
data.tar.gz: fd1d1139b115073c1f7bcec332dcdbbcd92c9ed7825acff34eaa7c3b76747e04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c29cc31ab4a5c6a834af31f12986c0e8e3b862d6603d117b7a3ca5792465636693542ae13417764c23fc2b6cfdd834bda7db0915d419157b329aec836fc7d2b2
|
7
|
+
data.tar.gz: 2390811743a6a997ee6d0ec2bba40ca5f27222ac14d352a51eb508e0e345c3f2190a12105bb3e9cfd63dc45052cdbe41d0c3c4df2dcf319103ec00f16db162a1
|
@@ -7,6 +7,10 @@ module EacConfig
|
|
7
7
|
PART_SEPARATOR = '.'
|
8
8
|
|
9
9
|
class << self
|
10
|
+
def assert(source)
|
11
|
+
source.is_a?(self) ? source : new(build_parts(source))
|
12
|
+
end
|
13
|
+
|
10
14
|
def build_parts(source)
|
11
15
|
return validate_parts!(source.split(PART_SEPARATOR)) if source.is_a?(::String)
|
12
16
|
return validate_parts!(source.flat_map { |part| build_parts(part) }) if
|
@@ -26,8 +30,8 @@ module EacConfig
|
|
26
30
|
|
27
31
|
attr_reader :parts
|
28
32
|
|
29
|
-
def initialize(
|
30
|
-
@parts =
|
33
|
+
def initialize(parts)
|
34
|
+
@parts = parts.to_a.freeze
|
31
35
|
end
|
32
36
|
end
|
33
37
|
end
|
@@ -10,13 +10,23 @@ module EacConfig
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
+
def result_from_load_path_uncached
|
14
|
+
node.recursive_loaded_nodes.lazy.map { |loaded_node| loaded_node.entry(path) }.find(&:found?)
|
15
|
+
end
|
16
|
+
|
17
|
+
def result_from_self_uncached
|
18
|
+
return nil unless paths_hash.key?(to_paths_hash_key)
|
19
|
+
|
20
|
+
::EacConfig::Entry.new(node, path, true, paths_hash.fetch(to_paths_hash_key))
|
21
|
+
end
|
22
|
+
|
23
|
+
def result_not_found_uncached
|
24
|
+
::EacConfig::Entry.new(nil, path, false, nil)
|
25
|
+
end
|
26
|
+
|
13
27
|
# @return [EacConfig::Entry]
|
14
28
|
def result_uncached
|
15
|
-
|
16
|
-
::EacConfig::Entry.new(node, path, true, paths_hash.fetch(to_paths_hash_key))
|
17
|
-
else
|
18
|
-
::EacConfig::Entry.new(nil, path, false, nil)
|
19
|
-
end
|
29
|
+
result_from_self || result_from_load_path || result_not_found
|
20
30
|
end
|
21
31
|
|
22
32
|
# @return [EacConfig::PathsHash]
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacConfig
|
6
|
+
class LoadNodesSearch
|
7
|
+
common_constructor :root_node do
|
8
|
+
add_next_pending until pending.empty?
|
9
|
+
end
|
10
|
+
|
11
|
+
def result
|
12
|
+
added
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def added
|
18
|
+
@added ||= []
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_next_pending
|
22
|
+
current = pending.pop
|
23
|
+
current.self_loaded_nodes.each do |loaded_node|
|
24
|
+
next if added.include?(loaded_node)
|
25
|
+
|
26
|
+
added << loaded_node
|
27
|
+
pending.push(loaded_node)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def pending
|
32
|
+
@pending ||= begin
|
33
|
+
r = Queue.new
|
34
|
+
r.push(root_node)
|
35
|
+
r
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_config/entry_path'
|
4
|
+
require 'eac_config/load_nodes_search'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
|
7
|
+
module EacConfig
|
8
|
+
module Node
|
9
|
+
common_concern do
|
10
|
+
enable_abstract_methods
|
11
|
+
include ::Comparable
|
12
|
+
end
|
13
|
+
|
14
|
+
LOAD_PATH_ENTRY_PATH = ::EacConfig::EntryPath.assert(%w[load_path])
|
15
|
+
LOAD_PATH_PATH_SEPARATOR = ':'
|
16
|
+
|
17
|
+
def entry(path)
|
18
|
+
::EacConfig::EntrySearch.new(self, ::EacConfig::EntryPath.assert(path)).result
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [Addressable::URI]
|
22
|
+
def url
|
23
|
+
raise_abstract_method(__method__)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [Array<EacConfig::Node>]
|
27
|
+
def self_loaded_nodes
|
28
|
+
::EacConfig::EntrySearch.new(self, ::EacConfig::EntryPath.assert(LOAD_PATH_ENTRY_PATH))
|
29
|
+
.result_from_self.if_present([]) do |e|
|
30
|
+
e.value.split(LOAD_PATH_PATH_SEPARATOR).map { |node_path| load_node(node_path) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Array<EacConfig::Node>]
|
35
|
+
def recursive_loaded_nodes
|
36
|
+
::EacConfig::LoadNodesSearch.new(self).result
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def load_node(node_path)
|
42
|
+
self.class.new(node_path.to_pathname.expand_path(path.parent))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/eac_config/version.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'addressable'
|
3
4
|
require 'eac_config/entry'
|
4
5
|
require 'eac_config/entry_search'
|
5
|
-
require 'eac_config/
|
6
|
-
require 'eac_config/writeable_node'
|
6
|
+
require 'eac_config/node'
|
7
7
|
require 'eac_ruby_utils/core_ext'
|
8
8
|
require 'eac_ruby_utils/yaml'
|
9
9
|
|
10
10
|
module EacConfig
|
11
11
|
class YamlFileNode
|
12
|
-
include ::EacConfig::
|
13
|
-
include ::EacConfig::WriteableNode
|
12
|
+
include ::EacConfig::Node
|
14
13
|
|
15
14
|
common_constructor :path do
|
16
15
|
self.path = path.to_pathname
|
@@ -20,8 +19,8 @@ module EacConfig
|
|
20
19
|
@data ||= ::EacRubyUtils::Yaml.load_file(path)
|
21
20
|
end
|
22
21
|
|
23
|
-
def
|
24
|
-
::
|
22
|
+
def url
|
23
|
+
::Addressable::URI.parse("file://#{path.expand_path}")
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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: 2021-05-
|
11
|
+
date: 2021-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: addressable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: eac_ruby_utils
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -48,14 +62,13 @@ files:
|
|
48
62
|
- lib/eac_config/entry.rb
|
49
63
|
- lib/eac_config/entry_path.rb
|
50
64
|
- lib/eac_config/entry_search.rb
|
51
|
-
- lib/eac_config/
|
65
|
+
- lib/eac_config/load_nodes_search.rb
|
66
|
+
- lib/eac_config/node.rb
|
52
67
|
- lib/eac_config/paths_hash.rb
|
53
68
|
- lib/eac_config/paths_hash/entry_key_error.rb
|
54
69
|
- lib/eac_config/paths_hash/node.rb
|
55
70
|
- lib/eac_config/paths_hash/path_search.rb
|
56
|
-
- lib/eac_config/readable_node.rb
|
57
71
|
- lib/eac_config/version.rb
|
58
|
-
- lib/eac_config/writeable_node.rb
|
59
72
|
- lib/eac_config/yaml_file_node.rb
|
60
73
|
homepage:
|
61
74
|
licenses: []
|
data/lib/eac_config/manager.rb
DELETED