open_config 1.2.0 → 2.0.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/open_config/files/base.rb +14 -22
- data/lib/open_config/files/json.rb +2 -2
- data/lib/open_config/files/yaml.rb +10 -6
- data/lib/open_config/files.rb +3 -3
- data/lib/open_config/node.rb +38 -0
- data/lib/open_config/version.rb +1 -1
- data/lib/open_config.rb +4 -3
- metadata +48 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7485c04b85ec19a76557a59fa05580e389331654256034244355f7170f0c40ee
|
4
|
+
data.tar.gz: 005d269f4976b68b409d066191b084bed432ee56ea68778a9f9ad40e45c83180
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdfce39a72ffb67790e54a84a9bc0c5f1257ce81baeb28fcef4061798b992ecc6dfcfca8e13267f0b6b67a408ad4c0289cfd6bc94b1c614dc41b86d57190d7a8
|
7
|
+
data.tar.gz: bc6fcf31e3082f58112750eb39ca6d7d2d3d2b643190651b98fc200f27cedc96ba49a56085a2bef05e9feba482a71fd1907a4c70b915dc0bff72b7afbd953210
|
@@ -1,41 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
class Base
|
5
|
-
attr_reader :file_path
|
6
|
-
|
7
|
-
def initialize(root: Dir.pwd, file:)
|
8
|
-
@file_path = File.join(root, file)
|
9
|
-
end
|
10
|
-
|
11
|
-
def method_missing(method_name, *arguments, &block)
|
12
|
-
return super unless configuration_method?(method_name)
|
3
|
+
require 'delegate'
|
13
4
|
|
14
|
-
|
5
|
+
module OpenConfig
|
6
|
+
class Base < DelegateClass(Node)
|
7
|
+
def initialize(path)
|
8
|
+
@path = path
|
9
|
+
super(build_config)
|
15
10
|
end
|
16
11
|
|
17
|
-
def
|
18
|
-
|
12
|
+
def ==(other)
|
13
|
+
return false unless other.kind_of?(OpenConfig::Base)
|
14
|
+
table! == other.table!
|
19
15
|
end
|
20
16
|
|
21
17
|
private
|
22
18
|
|
23
|
-
def
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
def tree
|
28
|
-
@tree ||= parse_file(read_file)
|
19
|
+
def build_config
|
20
|
+
parse_file(read_file)
|
29
21
|
end
|
30
22
|
|
31
23
|
def parse_file(_file_content)
|
32
|
-
raise NotImplementedError, '
|
24
|
+
raise NotImplementedError, 'Subclasses must implement #parse_file'
|
33
25
|
end
|
34
26
|
|
35
27
|
def read_file
|
36
|
-
raise OpenConfig::Errors::FileNotFound,
|
28
|
+
raise OpenConfig::Errors::FileNotFound, @path unless File.exists?(@path)
|
37
29
|
|
38
|
-
File.
|
30
|
+
File.read(@path)
|
39
31
|
end
|
40
32
|
end
|
41
33
|
end
|
@@ -3,11 +3,11 @@
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
module OpenConfig
|
6
|
-
class JSON <
|
6
|
+
class JSON < Base
|
7
7
|
private
|
8
8
|
|
9
9
|
def parse_file(file_content)
|
10
|
-
::JSON.parse(file_content, object_class:
|
10
|
+
::JSON.parse(file_content, object_class: OpenConfig::Node)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -5,19 +5,23 @@ require 'json'
|
|
5
5
|
require 'erb'
|
6
6
|
|
7
7
|
module OpenConfig
|
8
|
-
class YAML <
|
8
|
+
class YAML < Base
|
9
9
|
private
|
10
10
|
|
11
11
|
def parse_file(file_content)
|
12
|
-
::JSON.parse(
|
12
|
+
::JSON.parse(load_yaml(file_content).to_json, object_class: OpenConfig::Node)
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
15
|
+
def load_yaml(file_content)
|
16
|
+
begin
|
17
|
+
::YAML.load(compile(file_content), aliases: true)
|
18
|
+
rescue ArgumentError
|
19
|
+
::YAML.load(compile(file_content))
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
|
-
def
|
20
|
-
::ERB.new(file_content).result
|
23
|
+
def compile(file_content)
|
24
|
+
defined?(::ERB) ? ::ERB.new(file_content).result : file_content
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
data/lib/open_config/files.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module OpenConfig
|
6
|
+
class Node < OpenStruct
|
7
|
+
def fetch(name, *args, &block)
|
8
|
+
begin
|
9
|
+
name = name.to_sym
|
10
|
+
rescue NoMethodError
|
11
|
+
raise! TypeError, "#{name} is not a symbol nor a string"
|
12
|
+
end
|
13
|
+
|
14
|
+
table.fetch(name, *args, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_h
|
18
|
+
super.transform_values do |value|
|
19
|
+
value.instance_of?(self.class) ? value.to_h : value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def pretty_print(q)
|
24
|
+
q.object_group self do
|
25
|
+
q.nest(1) do
|
26
|
+
q.breakable
|
27
|
+
q.seplist(table, nil, :each) do |key, value|
|
28
|
+
q.group do
|
29
|
+
q.text key.to_s
|
30
|
+
q.text ': '
|
31
|
+
q.pp value
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/open_config/version.rb
CHANGED
data/lib/open_config.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require 'open_config/version'
|
4
|
+
require 'open_config/node'
|
5
|
+
require 'open_config/files'
|
6
|
+
require 'open_config/errors'
|
6
7
|
|
7
8
|
module OpenConfig
|
8
9
|
end
|
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Egor Iskrenkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
12
|
-
dependencies:
|
11
|
+
date: 2022-05-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.8'
|
13
55
|
description:
|
14
56
|
email:
|
15
57
|
- egor@iskrenkov.me
|
@@ -23,6 +65,7 @@ files:
|
|
23
65
|
- lib/open_config/files/base.rb
|
24
66
|
- lib/open_config/files/json.rb
|
25
67
|
- lib/open_config/files/yaml.rb
|
68
|
+
- lib/open_config/node.rb
|
26
69
|
- lib/open_config/version.rb
|
27
70
|
homepage: https://github.com/eiskrenkov/open_config
|
28
71
|
licenses:
|
@@ -36,14 +79,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
79
|
requirements:
|
37
80
|
- - ">="
|
38
81
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
82
|
+
version: '2.4'
|
40
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
84
|
requirements:
|
42
85
|
- - ">="
|
43
86
|
- !ruby/object:Gem::Version
|
44
87
|
version: '0'
|
45
88
|
requirements: []
|
46
|
-
rubygems_version: 3.
|
89
|
+
rubygems_version: 3.3.7
|
47
90
|
signing_key:
|
48
91
|
specification_version: 4
|
49
92
|
summary: Building OpenStruct trees from configuration files
|