evt-settings 1.1.0.1 → 2.1.1.4
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 -3
- data/lib/settings/controls/data.rb +0 -10
- data/lib/settings/data_source.rb +0 -2
- data/lib/settings/data_source/build.rb +1 -0
- data/lib/settings/data_source/env.rb +11 -0
- data/lib/settings/data_source/file.rb +5 -35
- data/lib/settings/data_source/hash.rb +0 -4
- data/lib/settings/setting/assignment.rb +4 -39
- data/lib/settings/setting/macro.rb +1 -6
- data/lib/settings/settings.rb +4 -43
- metadata +8 -22
- data/lib/settings/log.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d60fe7aaeb7fa586d01e6943cbcc04d9a5529d6fa8580fbfe214adc3f3abf3ff
|
4
|
+
data.tar.gz: 53a382d59cf56ee911a0526a2e87b2dd6acdf7eb90f06191001ea3cc00297130
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1668fcb8f29f99023233acdcc3b6bd5e78fc62c15151a2b013d5453184555aabdf52bca57a40bad3b49550d822d4d5432f45dfd2ef5723a9484c37ee784ff20f
|
7
|
+
data.tar.gz: 020c083f30538e64d70d43daab6e5519e39fd012cc0569b937cd5dc8d697a49f259baf4442ac469f1a0355083c1857a232909773fa15261ac4a294efb67761ac
|
data/lib/settings.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
require 'log'
|
5
|
-
require 'casing'
|
6
4
|
require 'attribute'
|
7
5
|
|
8
|
-
require 'settings/log'
|
9
6
|
require 'settings/data_source'
|
10
7
|
require 'settings/data_source/hash'
|
8
|
+
require 'settings/data_source/env'
|
11
9
|
require 'settings/data_source/file'
|
12
10
|
require 'settings/data_source/build'
|
13
11
|
require 'settings/registry'
|
data/lib/settings/data_source.rb
CHANGED
@@ -10,6 +10,7 @@ class Settings
|
|
10
10
|
def self.type(input=nil)
|
11
11
|
return Settings::DataSource::Hash if input.is_a?(::Hash)
|
12
12
|
return Settings::DataSource::File if input.is_a?(String) || input.nil?
|
13
|
+
return Settings::DataSource::Env if input.instance_of?(Object)
|
13
14
|
|
14
15
|
raise Settings::Error, "Input is not supported: #{input}"
|
15
16
|
end
|
@@ -2,13 +2,9 @@ class Settings
|
|
2
2
|
class DataSource
|
3
3
|
class File < DataSource
|
4
4
|
def self.canonize(source)
|
5
|
-
logger.trace { "Canonizing the file source (Source: #{source})" }
|
6
|
-
|
7
5
|
canonized_filepath = canonize_filepath(source)
|
8
6
|
validate(canonized_filepath)
|
9
7
|
|
10
|
-
logger.debug { "Canonized the file source (Source: #{source}, Canonized: #{canonized_filepath})" }
|
11
|
-
|
12
8
|
canonized_filepath
|
13
9
|
end
|
14
10
|
|
@@ -28,8 +24,6 @@ class Settings
|
|
28
24
|
dirpath ||= Pathname.new(source)
|
29
25
|
filepath ||= Pathname.new(source)
|
30
26
|
|
31
|
-
logger.debug { "Canonized the file source (#{source})" }
|
32
|
-
|
33
27
|
pathname(filepath, dirpath)
|
34
28
|
end
|
35
29
|
|
@@ -57,56 +51,32 @@ class Settings
|
|
57
51
|
end
|
58
52
|
|
59
53
|
def self.validate(pathname)
|
60
|
-
logger.trace { "Validating the pathname (#{pathname})" }
|
61
|
-
|
62
54
|
pathname = Pathname.new(pathname)
|
63
55
|
|
64
56
|
unless pathname.file?
|
65
|
-
|
66
|
-
logger.error { msg }
|
67
|
-
raise Settings::Error, msg
|
57
|
+
raise Settings::Error, "Settings cannot be read from #{pathname}. The file doesn't exist."
|
68
58
|
end
|
69
|
-
|
70
|
-
logger.trace { "Validated the pathname (#{pathname})" }
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.logger
|
74
|
-
@logger ||= Log.get(self)
|
75
59
|
end
|
76
60
|
|
77
61
|
def get_data
|
78
|
-
logger.trace { "Reading file: #{source}" }
|
79
62
|
file = ::File.open(source)
|
80
|
-
|
81
|
-
|
82
|
-
end
|
63
|
+
|
64
|
+
data = JSON.load(file)
|
83
65
|
|
84
66
|
hash_data_source = Hash.build data
|
85
67
|
hash_data_source.get_data
|
86
68
|
end
|
87
69
|
|
88
70
|
module Defaults
|
89
|
-
def self.logger
|
90
|
-
@logger ||= Log.get(self)
|
91
|
-
end
|
92
|
-
|
93
71
|
def self.filename
|
94
|
-
|
95
|
-
logger.debug { "Using the default settings file name (#{default_file})" }
|
96
|
-
default_file
|
72
|
+
'settings.json'
|
97
73
|
end
|
98
74
|
end
|
99
75
|
|
100
76
|
module Directory
|
101
77
|
module Defaults
|
102
|
-
def self.logger
|
103
|
-
@logger ||= Log.get(self)
|
104
|
-
end
|
105
|
-
|
106
78
|
def self.pathname
|
107
|
-
|
108
|
-
logger.debug { "Using the working directory default settings directory (#{default_dir})" }
|
109
|
-
default_dir
|
79
|
+
Dir.pwd
|
110
80
|
end
|
111
81
|
end
|
112
82
|
end
|
@@ -3,10 +3,6 @@ class Settings
|
|
3
3
|
module Assignment
|
4
4
|
extend self
|
5
5
|
|
6
|
-
def logger
|
7
|
-
@logger ||= Log.get(self)
|
8
|
-
end
|
9
|
-
|
10
6
|
def assign(receiver, attribute, value, strict=false)
|
11
7
|
settable = assure_settable(receiver, attribute, strict)
|
12
8
|
if settable
|
@@ -17,11 +13,7 @@ class Settings
|
|
17
13
|
end
|
18
14
|
|
19
15
|
def assign_value(receiver, attribute, value)
|
20
|
-
|
21
|
-
receiver.public_send("#{attribute}=", value).tap do
|
22
|
-
logger.debug { "Assigned to #{attribute}" }
|
23
|
-
logger.debug(tag: :data) { "#{attribute}: #{value}" }
|
24
|
-
end
|
16
|
+
receiver.public_send("#{attribute}=", value)
|
25
17
|
end
|
26
18
|
|
27
19
|
def setting?(receiver, attribute)
|
@@ -37,40 +29,22 @@ class Settings
|
|
37
29
|
:"#{attribute.to_s}=" unless attribute.to_s.end_with? '='
|
38
30
|
end
|
39
31
|
|
40
|
-
def digest(receiver, attribute, strict)
|
41
|
-
content = []
|
42
|
-
content << "Attribute: #{attribute}" if attribute
|
43
|
-
content << "Receiver: #{receiver.class.name}"
|
44
|
-
strict = "<not set>" if strict.nil?
|
45
|
-
content << "Strict: #{strict}"
|
46
|
-
content.join ', '
|
47
|
-
end
|
48
|
-
|
49
32
|
module Object
|
50
33
|
extend Assignment
|
51
34
|
|
52
|
-
def logger
|
53
|
-
@logger ||= Log.get(self)
|
54
|
-
end
|
55
|
-
|
56
35
|
def self.assure_settable(receiver, attribute, strict=true)
|
57
|
-
logger.trace { "Approving attribute (#{digest(receiver, attribute, strict)})" }
|
58
|
-
|
59
36
|
if strict
|
60
37
|
setting = setting?(receiver, attribute)
|
61
38
|
unless setting
|
62
|
-
logger.warn { "Can't set \"#{attribute}\". It isn't a setting of #{receiver.class.name}." }
|
63
39
|
return false
|
64
40
|
end
|
65
41
|
end
|
66
42
|
|
67
43
|
assignable = assignable? receiver, attribute
|
68
44
|
unless assignable
|
69
|
-
logger.warn { "Can't set \"#{attribute}\". It isn't assignable to #{receiver.class.name}." }
|
70
45
|
return false
|
71
46
|
end
|
72
47
|
|
73
|
-
logger.debug { "\"#{attribute}\" can be set" }
|
74
48
|
true
|
75
49
|
end
|
76
50
|
end
|
@@ -78,28 +52,19 @@ class Settings
|
|
78
52
|
module Attribute
|
79
53
|
extend Assignment
|
80
54
|
|
81
|
-
def logger
|
82
|
-
@logger ||= Log.get(self)
|
83
|
-
end
|
84
|
-
|
85
55
|
def self.assure_settable(receiver, attribute, strict=true)
|
86
56
|
if strict
|
87
57
|
setting = setting? receiver, attribute
|
88
58
|
unless setting
|
89
|
-
|
90
|
-
logger.error { msg }
|
91
|
-
raise msg
|
59
|
+
raise "Can't set \"#{attribute}\". It isn't a setting of #{receiver.class.name}."
|
92
60
|
end
|
93
61
|
end
|
94
62
|
|
95
|
-
assignable = assignable?
|
63
|
+
assignable = assignable?(receiver, attribute)
|
96
64
|
unless assignable
|
97
|
-
|
98
|
-
logger.error { msg }
|
99
|
-
raise msg
|
65
|
+
raise "Can't set \"#{attribute}\". It isn't assignable to #{receiver.class.name}."
|
100
66
|
end
|
101
67
|
|
102
|
-
logger.debug { "\"#{attribute}\" can be set" }
|
103
68
|
true
|
104
69
|
end
|
105
70
|
end
|
@@ -2,13 +2,8 @@ class Settings
|
|
2
2
|
module Setting
|
3
3
|
module Macro
|
4
4
|
def setting_macro(attribute)
|
5
|
-
logger = Log.get(self)
|
6
|
-
|
7
|
-
logger.trace { "Defining setting attribute: #{attribute}" }
|
8
5
|
Attribute::Define.(self, attribute, :accessor)
|
9
|
-
Settings::Registry.register(self, attribute)
|
10
|
-
logger.debug { "Defined setting attribute: #{attribute}" }
|
11
|
-
end
|
6
|
+
Settings::Registry.register(self, attribute)
|
12
7
|
end
|
13
8
|
alias :setting :setting_macro
|
14
9
|
end
|
data/lib/settings/settings.rb
CHANGED
@@ -1,18 +1,12 @@
|
|
1
1
|
class Settings
|
2
2
|
class Error < RuntimeError; end
|
3
3
|
|
4
|
-
include Log::Dependency
|
5
|
-
|
6
4
|
attr_reader :data
|
7
5
|
|
8
6
|
def initialize(data)
|
9
7
|
@data = data
|
10
8
|
end
|
11
9
|
|
12
|
-
def self.logger
|
13
|
-
@logger ||= Log.get(self)
|
14
|
-
end
|
15
|
-
|
16
10
|
def self.build(source=nil)
|
17
11
|
source ||= implementer_source
|
18
12
|
|
@@ -20,28 +14,20 @@ class Settings
|
|
20
14
|
|
21
15
|
data = data_source.get_data
|
22
16
|
|
23
|
-
data = Casing::Underscore.(data)
|
24
|
-
|
25
17
|
instance = new(data)
|
26
18
|
|
27
19
|
instance
|
28
20
|
end
|
29
21
|
|
30
22
|
def self.implementer_source
|
31
|
-
|
32
|
-
|
33
|
-
unless self.respond_to? :data_source
|
34
|
-
logger.trace { "Implementer doesn't provide a data_source" }
|
23
|
+
unless self.respond_to?(:data_source)
|
35
24
|
return nil
|
36
25
|
end
|
37
26
|
|
38
|
-
self.data_source
|
39
|
-
logger.trace { "Got data source from the implementer (#{data_source})" }
|
40
|
-
end
|
27
|
+
self.data_source
|
41
28
|
end
|
42
29
|
|
43
30
|
def set(receiver, *namespace, attribute: nil, strict: true)
|
44
|
-
logger.trace { "Setting #{receiver.class.name} (#{digest(namespace, attribute, strict)})" }
|
45
31
|
unless attribute.nil?
|
46
32
|
value = set_attribute(receiver, attribute, namespace, strict)
|
47
33
|
else
|
@@ -51,8 +37,6 @@ class Settings
|
|
51
37
|
end
|
52
38
|
|
53
39
|
def set_attribute(receiver, attribute, namespace, strict)
|
54
|
-
logger.trace { "Setting #{receiver.class.name} attribute (#{digest(namespace, attribute, strict)})" }
|
55
|
-
|
56
40
|
attribute = attribute.to_s if attribute.is_a?(Symbol)
|
57
41
|
|
58
42
|
attribute_namespace = namespace.dup
|
@@ -61,35 +45,25 @@ class Settings
|
|
61
45
|
value = get(attribute_namespace)
|
62
46
|
|
63
47
|
if value.nil?
|
64
|
-
|
65
|
-
logger.error { msg }
|
66
|
-
raise Settings::Error, msg
|
48
|
+
raise Settings::Error, "#{attribute_namespace} not found in the data"
|
67
49
|
end
|
68
50
|
|
69
51
|
Settings::Setting::Assignment::Attribute.assign(receiver, attribute.to_sym, value, strict)
|
70
52
|
|
71
|
-
logger.debug { "Set #{receiver.class.name} #{attribute} to #{value.inspect}" }
|
72
|
-
|
73
53
|
value
|
74
54
|
end
|
75
55
|
|
76
56
|
def set_object(receiver, namespace, strict)
|
77
|
-
logger.trace { "Setting #{receiver.class.name} object (#{digest(namespace, nil, strict)})" }
|
78
|
-
|
79
57
|
data = get(namespace)
|
80
58
|
|
81
59
|
if data.nil?
|
82
|
-
|
83
|
-
logger.error { msg }
|
84
|
-
raise Settings::Error, msg
|
60
|
+
raise Settings::Error, "#{namespace} not found in the data"
|
85
61
|
end
|
86
62
|
|
87
63
|
data.each do |attribute, value|
|
88
64
|
Settings::Setting::Assignment::Object.assign(receiver, attribute.to_sym, value, strict)
|
89
65
|
end
|
90
66
|
|
91
|
-
logger.debug { "Set #{receiver.class.name} object (#{digest(namespace, nil, strict)})" }
|
92
|
-
|
93
67
|
receiver
|
94
68
|
end
|
95
69
|
|
@@ -99,7 +73,6 @@ class Settings
|
|
99
73
|
|
100
74
|
def get(*namespace)
|
101
75
|
namespace.flatten!
|
102
|
-
logger.trace { "Getting #{namespace}" }
|
103
76
|
|
104
77
|
keys = namespace.map { |n| n.is_a?(Symbol) ? n.to_s : n }
|
105
78
|
|
@@ -110,18 +83,6 @@ class Settings
|
|
110
83
|
value = data.dig(*keys)
|
111
84
|
end
|
112
85
|
|
113
|
-
logger.debug { "Got #{namespace}" }
|
114
|
-
logger.debug(tag: :data) { "#{namespace}: #{value.inspect}" }
|
115
|
-
|
116
86
|
value
|
117
87
|
end
|
118
|
-
|
119
|
-
def digest(namespace, attribute, strict)
|
120
|
-
content = []
|
121
|
-
content << "Namespace: #{namespace.join ', '}" unless namespace.empty?
|
122
|
-
content << "Attribute: #{attribute}" if attribute
|
123
|
-
strict = "<not set>" if strict.nil?
|
124
|
-
content << "Strict: #{strict}"
|
125
|
-
content.join ', '
|
126
|
-
end
|
127
88
|
end
|
metadata
CHANGED
@@ -1,31 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evt-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 2.1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: evt-
|
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'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: evt-casing
|
14
|
+
name: evt-attribute
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - ">="
|
@@ -66,9 +52,9 @@ files:
|
|
66
52
|
- lib/settings/controls/subject.rb
|
67
53
|
- lib/settings/data_source.rb
|
68
54
|
- lib/settings/data_source/build.rb
|
55
|
+
- lib/settings/data_source/env.rb
|
69
56
|
- lib/settings/data_source/file.rb
|
70
57
|
- lib/settings/data_source/hash.rb
|
71
|
-
- lib/settings/log.rb
|
72
58
|
- lib/settings/registry.rb
|
73
59
|
- lib/settings/setting.rb
|
74
60
|
- lib/settings/setting/assignment.rb
|
@@ -78,7 +64,7 @@ homepage: https://github.com/eventide-project/settings
|
|
78
64
|
licenses:
|
79
65
|
- MIT
|
80
66
|
metadata: {}
|
81
|
-
post_install_message:
|
67
|
+
post_install_message:
|
82
68
|
rdoc_options: []
|
83
69
|
require_paths:
|
84
70
|
- lib
|
@@ -93,8 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
79
|
- !ruby/object:Gem::Version
|
94
80
|
version: '0'
|
95
81
|
requirements: []
|
96
|
-
rubygems_version: 3.
|
97
|
-
signing_key:
|
82
|
+
rubygems_version: 3.1.2
|
83
|
+
signing_key:
|
98
84
|
specification_version: 4
|
99
85
|
summary: Settings data access and assignment
|
100
86
|
test_files: []
|