evt-settings 1.0.0.0 → 1.1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/settings.rb +1 -2
- data/lib/settings/controls.rb +1 -0
- data/lib/settings/controls/data.rb +54 -0
- data/lib/settings/controls/data_source.rb +11 -3
- data/lib/settings/controls/settings.rb +11 -51
- data/lib/settings/{data_source/data_source.rb → data_source.rb} +6 -0
- data/lib/settings/data_source/file.rb +9 -13
- data/lib/settings/data_source/hash.rb +19 -6
- data/lib/settings/settings.rb +9 -17
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0abfcafdd139db015431e84676760b936413ad7696992d6af088399ae8a5e2d
|
4
|
+
data.tar.gz: fe15fdf903dc1ccc275b56acc430397fb69fef737cc778ffd1cd41de2d15a743
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 398a50b88b43b5994140d9cc71041c5dfd683ccf0108ea0b083131e91f16cba7870ca9fd9b31dcf222ff1ace5205e42de554b4b7d5d2586c406c1cff45131892
|
7
|
+
data.tar.gz: 36db77a43d48881b8d77c5d95122990c1c9894caf1b0f44bd5da42f419c93c2be7a3824601172a82d3945382dd8ab262e7594e17b7c6ec5a98a3ed355d7fb1c8
|
data/lib/settings.rb
CHANGED
@@ -4,10 +4,9 @@ require 'json'
|
|
4
4
|
require 'log'
|
5
5
|
require 'casing'
|
6
6
|
require 'attribute'
|
7
|
-
require 'confstruct'
|
8
7
|
|
9
8
|
require 'settings/log'
|
10
|
-
require 'settings/data_source
|
9
|
+
require 'settings/data_source'
|
11
10
|
require 'settings/data_source/hash'
|
12
11
|
require 'settings/data_source/file'
|
13
12
|
require 'settings/data_source/build'
|
data/lib/settings/controls.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
class Settings
|
2
|
+
module Controls
|
3
|
+
module Data
|
4
|
+
module Flat
|
5
|
+
module Single
|
6
|
+
def self.example
|
7
|
+
{
|
8
|
+
'some_setting' => 'some value'
|
9
|
+
}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Multiple
|
14
|
+
def self.example
|
15
|
+
{
|
16
|
+
'some_setting' => 'some value',
|
17
|
+
'some_other_setting' => 'some other value',
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Hierarchical
|
24
|
+
def self.example
|
25
|
+
{
|
26
|
+
'some_namespace' => {
|
27
|
+
'some_setting' => 'some value'
|
28
|
+
}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module CamelCaseKeys
|
34
|
+
def self.example
|
35
|
+
{
|
36
|
+
'someNamespace' => {
|
37
|
+
'someSetting' => 'some value'
|
38
|
+
}
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module SymbolKeys
|
44
|
+
def self.example
|
45
|
+
{
|
46
|
+
:some_namespace => {
|
47
|
+
:some_setting => 'some value'
|
48
|
+
}
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -7,9 +7,17 @@ class Settings
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.data
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
Data::Flat::Single.example
|
11
|
+
end
|
12
|
+
|
13
|
+
module SymbolKeys
|
14
|
+
def self.example
|
15
|
+
::Settings::DataSource::Hash.build(data)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.data
|
19
|
+
Data::SymbolKeys.example
|
20
|
+
end
|
13
21
|
end
|
14
22
|
end
|
15
23
|
|
@@ -3,84 +3,44 @@ class Settings
|
|
3
3
|
module Settings
|
4
4
|
module SettingAttribute
|
5
5
|
def self.example
|
6
|
-
::Settings.
|
6
|
+
::Settings.build(data)
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.data
|
10
|
-
|
11
|
-
"some_setting" => "some value"
|
12
|
-
}
|
10
|
+
Data::Flat::Single.example
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
16
|
-
module
|
14
|
+
module PartialMatch
|
17
15
|
def self.example
|
18
|
-
::Settings.
|
16
|
+
::Settings.build(data)
|
19
17
|
end
|
20
18
|
|
21
19
|
def self.data
|
22
|
-
|
23
|
-
"some_setting" => "some value",
|
24
|
-
"some_other_setting" => "some other value",
|
25
|
-
"yet_another_setting" => "yet another value"
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
module Partial
|
30
|
-
def self.example
|
31
|
-
::Settings.new(data)
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.data
|
35
|
-
{
|
36
|
-
"some_setting" => "some value",
|
37
|
-
"some_other_setting" => "some other value",
|
38
|
-
}
|
39
|
-
end
|
20
|
+
Data::Flat::Multiple.example
|
40
21
|
end
|
41
22
|
end
|
42
23
|
|
43
|
-
module
|
24
|
+
module Namespace
|
44
25
|
def self.example
|
45
|
-
::Settings.
|
26
|
+
::Settings.build(data)
|
46
27
|
end
|
47
28
|
|
48
29
|
def self.data
|
49
|
-
|
50
|
-
"some_accessor_attribute" => "some accessor value"
|
51
|
-
}
|
30
|
+
Data::Hierarchical.example
|
52
31
|
end
|
53
32
|
end
|
54
33
|
|
55
|
-
module
|
34
|
+
module AccessorAttribute
|
56
35
|
def self.example
|
57
|
-
::Settings.
|
36
|
+
::Settings.build(data)
|
58
37
|
end
|
59
38
|
|
60
39
|
def self.data
|
61
40
|
{
|
62
|
-
|
63
|
-
"some_setting" => "some value"
|
64
|
-
}
|
41
|
+
'some_accessor_attribute' => 'some accessor value'
|
65
42
|
}
|
66
43
|
end
|
67
|
-
|
68
|
-
module Override
|
69
|
-
def self.example
|
70
|
-
s = ::Settings.build(Namespace.data)
|
71
|
-
s.override(data)
|
72
|
-
s
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.data
|
76
|
-
{
|
77
|
-
"some_namespace" => {
|
78
|
-
"some_setting" => "some overridden value",
|
79
|
-
"some_other_setting" => "some other value"
|
80
|
-
}
|
81
|
-
}
|
82
|
-
end
|
83
|
-
end
|
84
44
|
end
|
85
45
|
end
|
86
46
|
end
|
@@ -1,22 +1,18 @@
|
|
1
1
|
class Settings
|
2
2
|
class DataSource
|
3
3
|
class File < DataSource
|
4
|
-
def self.
|
5
|
-
|
6
|
-
validate(canonical)
|
4
|
+
def self.canonize(source)
|
5
|
+
logger.trace { "Canonizing the file source (Source: #{source})" }
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
canonized_filepath = canonize_filepath(source)
|
8
|
+
validate(canonized_filepath)
|
10
9
|
|
11
|
-
|
12
|
-
logger.trace { "Canonizing the file source (#{source})" }
|
10
|
+
logger.debug { "Canonized the file source (Source: #{source}, Canonized: #{canonized_filepath})" }
|
13
11
|
|
14
|
-
|
15
|
-
logger.debug { "Canonized the file source (#{source})" }
|
16
|
-
end
|
12
|
+
canonized_filepath
|
17
13
|
end
|
18
14
|
|
19
|
-
def self.
|
15
|
+
def self.canonize_filepath(source)
|
20
16
|
return default_filepath if source.nil?
|
21
17
|
return source if full_path?(source)
|
22
18
|
|
@@ -32,6 +28,8 @@ class Settings
|
|
32
28
|
dirpath ||= Pathname.new(source)
|
33
29
|
filepath ||= Pathname.new(source)
|
34
30
|
|
31
|
+
logger.debug { "Canonized the file source (#{source})" }
|
32
|
+
|
35
33
|
pathname(filepath, dirpath)
|
36
34
|
end
|
37
35
|
|
@@ -83,8 +81,6 @@ class Settings
|
|
83
81
|
logger.debug { "Read file: #{source}" }
|
84
82
|
end
|
85
83
|
|
86
|
-
data = Casing::Underscore.(data)
|
87
|
-
|
88
84
|
hash_data_source = Hash.build data
|
89
85
|
hash_data_source.get_data
|
90
86
|
end
|
@@ -5,14 +5,27 @@ class Settings
|
|
5
5
|
@logger ||= Log.get(self)
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
9
|
-
|
8
|
+
def get_data
|
9
|
+
AssureStringKeys.(source)
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
module AssureStringKeys
|
13
|
+
def self.call(data)
|
14
|
+
new_data = {}
|
15
|
+
|
16
|
+
data.each do |key, value|
|
17
|
+
new_key = key.to_s
|
18
|
+
|
19
|
+
if value.is_a?(::Hash)
|
20
|
+
new_value = self.(value)
|
21
|
+
else
|
22
|
+
new_value = value
|
23
|
+
end
|
24
|
+
|
25
|
+
new_data[new_key] = new_value
|
26
|
+
end
|
27
|
+
|
28
|
+
new_data
|
16
29
|
end
|
17
30
|
end
|
18
31
|
end
|
data/lib/settings/settings.rb
CHANGED
@@ -20,6 +20,8 @@ class Settings
|
|
20
20
|
|
21
21
|
data = data_source.get_data
|
22
22
|
|
23
|
+
data = Casing::Underscore.(data)
|
24
|
+
|
23
25
|
instance = new(data)
|
24
26
|
|
25
27
|
instance
|
@@ -38,21 +40,6 @@ class Settings
|
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
41
|
-
def override(override_data)
|
42
|
-
logger.trace { "Overriding settings data" }
|
43
|
-
res = data.push!(override_data)
|
44
|
-
logger.debug { "Overrode settings data" }
|
45
|
-
logger.debug(tag: :data) { "Override data #{override_data}" }
|
46
|
-
res
|
47
|
-
end
|
48
|
-
|
49
|
-
def reset
|
50
|
-
logger.trace { "Resetting overridden settings data" }
|
51
|
-
res = data.pop!
|
52
|
-
logger.debug { "Reset overridden settings data" }
|
53
|
-
res
|
54
|
-
end
|
55
|
-
|
56
43
|
def set(receiver, *namespace, attribute: nil, strict: true)
|
57
44
|
logger.trace { "Setting #{receiver.class.name} (#{digest(namespace, attribute, strict)})" }
|
58
45
|
unless attribute.nil?
|
@@ -114,9 +101,14 @@ class Settings
|
|
114
101
|
namespace.flatten!
|
115
102
|
logger.trace { "Getting #{namespace}" }
|
116
103
|
|
117
|
-
|
104
|
+
keys = namespace.map { |n| n.is_a?(Symbol) ? n.to_s : n }
|
118
105
|
|
119
|
-
value =
|
106
|
+
value = nil
|
107
|
+
if keys.empty?
|
108
|
+
value = data
|
109
|
+
else
|
110
|
+
value = data.dig(*keys)
|
111
|
+
end
|
120
112
|
|
121
113
|
logger.debug { "Got #{namespace}" }
|
122
114
|
logger.debug(tag: :data) { "#{namespace}: #{value.inspect}" }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evt-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evt-log
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: confstruct
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: test_bench
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,11 +60,12 @@ extra_rdoc_files: []
|
|
74
60
|
files:
|
75
61
|
- lib/settings.rb
|
76
62
|
- lib/settings/controls.rb
|
63
|
+
- lib/settings/controls/data.rb
|
77
64
|
- lib/settings/controls/data_source.rb
|
78
65
|
- lib/settings/controls/settings.rb
|
79
66
|
- lib/settings/controls/subject.rb
|
67
|
+
- lib/settings/data_source.rb
|
80
68
|
- lib/settings/data_source/build.rb
|
81
|
-
- lib/settings/data_source/data_source.rb
|
82
69
|
- lib/settings/data_source/file.rb
|
83
70
|
- lib/settings/data_source/hash.rb
|
84
71
|
- lib/settings/log.rb
|
@@ -106,8 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
93
|
- !ruby/object:Gem::Version
|
107
94
|
version: '0'
|
108
95
|
requirements: []
|
109
|
-
|
110
|
-
rubygems_version: 2.7.6
|
96
|
+
rubygems_version: 3.0.1
|
111
97
|
signing_key:
|
112
98
|
specification_version: 4
|
113
99
|
summary: Settings data access and assignment
|