qonfig 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +1 -1
- data/.rubocop.yml +1 -1
- data/.travis.yml +3 -3
- data/CHANGELOG.md +10 -0
- data/README.md +146 -1
- data/Rakefile +2 -0
- data/lib/qonfig/command_set.rb +53 -55
- data/lib/qonfig/commands/add_nested_option.rb +36 -40
- data/lib/qonfig/commands/add_option.rb +33 -37
- data/lib/qonfig/commands/base.rb +9 -13
- data/lib/qonfig/commands/compose.rb +29 -33
- data/lib/qonfig/commands/expose_yaml.rb +154 -158
- data/lib/qonfig/commands/load_from_env.rb +77 -79
- data/lib/qonfig/commands/load_from_json.rb +52 -56
- data/lib/qonfig/commands/load_from_self.rb +57 -61
- data/lib/qonfig/commands/load_from_yaml.rb +54 -58
- data/lib/qonfig/commands.rb +15 -0
- data/lib/qonfig/configurable.rb +88 -90
- data/lib/qonfig/data_set/class_builder.rb +17 -21
- data/lib/qonfig/data_set.rb +186 -138
- data/lib/qonfig/dsl.rb +106 -108
- data/lib/qonfig/{error.rb → exceptions.rb} +13 -1
- data/lib/qonfig/loaders/basic.rb +30 -32
- data/lib/qonfig/loaders/json.rb +16 -23
- data/lib/qonfig/loaders/yaml.rb +16 -23
- data/lib/qonfig/loaders.rb +9 -0
- data/lib/qonfig/plugins/abstract.rb +7 -11
- data/lib/qonfig/plugins/access_mixin.rb +21 -25
- data/lib/qonfig/plugins/registry.rb +120 -124
- data/lib/qonfig/plugins.rb +56 -54
- data/lib/qonfig/settings/builder.rb +10 -14
- data/lib/qonfig/settings/key_guard.rb +60 -64
- data/lib/qonfig/settings/lock.rb +53 -57
- data/lib/qonfig/settings.rb +392 -354
- data/lib/qonfig/uploaders/base.rb +18 -0
- data/lib/qonfig/uploaders/file.rb +55 -0
- data/lib/qonfig/uploaders/json.rb +35 -0
- data/lib/qonfig/uploaders/yaml.rb +93 -0
- data/lib/qonfig/uploaders.rb +10 -0
- data/lib/qonfig/version.rb +1 -1
- data/lib/qonfig.rb +4 -21
- data/qonfig.gemspec +1 -1
- metadata +13 -6
data/lib/qonfig/loaders/json.rb
CHANGED
@@ -1,31 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
# @api private
|
4
|
+
# @since 0.5.0
|
5
|
+
class Qonfig::Loaders::JSON < Qonfig::Loaders::Basic
|
6
|
+
class << self
|
7
|
+
# @param data [String]
|
8
|
+
# @return [Object]
|
9
|
+
#
|
5
10
|
# @api private
|
6
11
|
# @since 0.5.0
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
class << self
|
12
|
-
# @param data [String]
|
13
|
-
# @return [Object]
|
14
|
-
#
|
15
|
-
# @api private
|
16
|
-
# @since 0.5.0
|
17
|
-
def load(data)
|
18
|
-
::JSON.parse(data, max_nesting: false, allow_nan: true)
|
19
|
-
end
|
12
|
+
def load(data)
|
13
|
+
::JSON.parse(data, max_nesting: false, allow_nan: true)
|
14
|
+
end
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
16
|
+
# @return [Object]
|
17
|
+
#
|
18
|
+
# @api private
|
19
|
+
# @since 0.5.0
|
20
|
+
def load_empty_data
|
21
|
+
load('{}')
|
29
22
|
end
|
30
23
|
end
|
31
24
|
end
|
data/lib/qonfig/loaders/yaml.rb
CHANGED
@@ -1,31 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
# @api private
|
4
|
+
# @since 0.2.0
|
5
|
+
class Qonfig::Loaders::YAML < Qonfig::Loaders::Basic
|
6
|
+
class << self
|
7
|
+
# @param data [String]
|
8
|
+
# @return [Object]
|
9
|
+
#
|
5
10
|
# @api private
|
6
11
|
# @since 0.2.0
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
class << self
|
12
|
-
# @param data [String]
|
13
|
-
# @return [Object]
|
14
|
-
#
|
15
|
-
# @api private
|
16
|
-
# @since 0.2.0
|
17
|
-
def load(data)
|
18
|
-
::YAML.load(ERB.new(data).result)
|
19
|
-
end
|
12
|
+
def load(data)
|
13
|
+
::YAML.load(ERB.new(data).result)
|
14
|
+
end
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
16
|
+
# @return [Object]
|
17
|
+
#
|
18
|
+
# @api private
|
19
|
+
# @since 0.5.0
|
20
|
+
def load_empty_data
|
21
|
+
load('{}')
|
29
22
|
end
|
30
23
|
end
|
31
24
|
end
|
@@ -1,17 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
# @api private
|
4
|
+
# @since 0.4.0
|
5
|
+
class Qonfig::Plugins::Abstract
|
6
|
+
class << self
|
7
|
+
# @return [void]
|
8
|
+
#
|
5
9
|
# @api private
|
6
10
|
# @since 0.4.0
|
7
|
-
|
8
|
-
class << self
|
9
|
-
# @return [void]
|
10
|
-
#
|
11
|
-
# @api private
|
12
|
-
# @since 0.4.0
|
13
|
-
def load!; end
|
14
|
-
end
|
15
|
-
end
|
11
|
+
def load!; end
|
16
12
|
end
|
17
13
|
end
|
@@ -1,30 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
Qonfig::Plugins.load(plugin_name)
|
17
|
-
end
|
3
|
+
# @api private
|
4
|
+
# @since 0.4.0
|
5
|
+
module Qonfig::Plugins::AccessMixin
|
6
|
+
# @param plugin_name [Symbol, String]
|
7
|
+
# @return [void]
|
8
|
+
#
|
9
|
+
# @see Qonfig::Plugins
|
10
|
+
#
|
11
|
+
# @api public
|
12
|
+
# @since 0.4.0
|
13
|
+
def plugin(plugin_name)
|
14
|
+
Qonfig::Plugins.load(plugin_name)
|
15
|
+
end
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
17
|
+
# @return [Array<String>]
|
18
|
+
#
|
19
|
+
# @see Qonfig::Plugins
|
20
|
+
#
|
21
|
+
# @api public
|
22
|
+
# @since 0.4.0
|
23
|
+
def plugins
|
24
|
+
Qonfig::Plugins.names
|
29
25
|
end
|
30
26
|
end
|
@@ -1,129 +1,125 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
unless registered?(plugin_name)
|
113
|
-
raise Qonfig::UnregisteredPluginError, "#{plugin_name} plugin is not registered"
|
114
|
-
end
|
115
|
-
|
116
|
-
plugin_set[plugin_name]
|
117
|
-
end
|
118
|
-
|
119
|
-
# @param key [Symbol, String]
|
120
|
-
# @return [String]
|
121
|
-
#
|
122
|
-
# @api private
|
123
|
-
# @since 0.4.0
|
124
|
-
def indifferently_accessable_plugin_name(plugin_name)
|
125
|
-
plugin_name.to_s
|
126
|
-
end
|
3
|
+
# @api private
|
4
|
+
# @since 0.4.0
|
5
|
+
class Qonfig::Plugins::Registry
|
6
|
+
# @return [void]
|
7
|
+
#
|
8
|
+
# @api private
|
9
|
+
# @since 0.4.0
|
10
|
+
def initialize
|
11
|
+
@plugin_set = {}
|
12
|
+
@access_lock = Mutex.new
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param plugin_name [Symbol, String]
|
16
|
+
# @return [Qonfig::Plugins::Abstract]
|
17
|
+
#
|
18
|
+
# @api private
|
19
|
+
# @since 0.4.0
|
20
|
+
def [](plugin_name)
|
21
|
+
thread_safe { fetch(plugin_name) }
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param plugin_name [Symbol, String]
|
25
|
+
# @param plugin_module [Qonfig::Plugins::Abstract]
|
26
|
+
# @return [void]
|
27
|
+
#
|
28
|
+
# @api private
|
29
|
+
# @since 0.4.0
|
30
|
+
def register(plugin_name, plugin_module)
|
31
|
+
thread_safe { apply(plugin_name, plugin_module) }
|
32
|
+
end
|
33
|
+
alias_method :[]=, :register
|
34
|
+
|
35
|
+
# @return [Array<String>]
|
36
|
+
#
|
37
|
+
# @api private
|
38
|
+
# @since 0.4.0
|
39
|
+
def names
|
40
|
+
thread_safe { plugin_names }
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# @return [Hash]
|
46
|
+
#
|
47
|
+
# @api private
|
48
|
+
# @since 0.4.0
|
49
|
+
attr_reader :plugin_set
|
50
|
+
|
51
|
+
# @return [Mutex]
|
52
|
+
#
|
53
|
+
# @api private
|
54
|
+
# @since 0.4.0
|
55
|
+
attr_reader :access_lock
|
56
|
+
|
57
|
+
# @return [void]
|
58
|
+
#
|
59
|
+
# @api private
|
60
|
+
# @since 0.4.0
|
61
|
+
def thread_safe
|
62
|
+
access_lock.synchronize { yield if block_given? }
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [Array<String>]
|
66
|
+
#
|
67
|
+
# @api private
|
68
|
+
# @since 0.4.0
|
69
|
+
def plugin_names
|
70
|
+
plugin_set.keys
|
71
|
+
end
|
72
|
+
|
73
|
+
# @param plugin_name [String]
|
74
|
+
# @return [Boolean]
|
75
|
+
#
|
76
|
+
# @api private
|
77
|
+
# @since 0.4.0
|
78
|
+
def registered?(plugin_name)
|
79
|
+
plugin_set.key?(plugin_name)
|
80
|
+
end
|
81
|
+
|
82
|
+
# @param plugin_name [Symbol, String]
|
83
|
+
# @param plugin_module [Qonfig::Plugins::Abstract]
|
84
|
+
# @return [void]
|
85
|
+
#
|
86
|
+
# @raise [Qonfig::AlreadyRegisteredPluginError]
|
87
|
+
#
|
88
|
+
# @api private
|
89
|
+
# @since 0.4.0
|
90
|
+
def apply(plugin_name, plugin_module)
|
91
|
+
plugin_name = indifferently_accessable_plugin_name(plugin_name)
|
92
|
+
|
93
|
+
if registered?(plugin_name)
|
94
|
+
raise Qonfig::AlreadyRegisteredPluginError, "#{plugin_name} plugin already exist"
|
95
|
+
end
|
96
|
+
|
97
|
+
plugin_set[plugin_name] = plugin_module
|
98
|
+
end
|
99
|
+
|
100
|
+
# @param plugin_name [Symbol, String]
|
101
|
+
# @return [Qonfig::Plugins::Abstract]
|
102
|
+
#
|
103
|
+
# @raise [Qonfig::UnregisteredPluginError]
|
104
|
+
#
|
105
|
+
# @api private
|
106
|
+
# @since 0.4.0
|
107
|
+
def fetch(plugin_name)
|
108
|
+
plugin_name = indifferently_accessable_plugin_name(plugin_name)
|
109
|
+
|
110
|
+
unless registered?(plugin_name)
|
111
|
+
raise Qonfig::UnregisteredPluginError, "#{plugin_name} plugin is not registered"
|
127
112
|
end
|
113
|
+
|
114
|
+
plugin_set[plugin_name]
|
115
|
+
end
|
116
|
+
|
117
|
+
# @param key [Symbol, String]
|
118
|
+
# @return [String]
|
119
|
+
#
|
120
|
+
# @api private
|
121
|
+
# @since 0.4.0
|
122
|
+
def indifferently_accessable_plugin_name(plugin_name)
|
123
|
+
plugin_name.to_s
|
128
124
|
end
|
129
125
|
end
|
data/lib/qonfig/plugins.rb
CHANGED
@@ -1,62 +1,64 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
# @api public
|
4
|
+
# @since 0.4.0
|
5
|
+
module Qonfig::Plugins
|
6
|
+
require_relative 'plugins/registry'
|
7
|
+
require_relative 'plugins/access_mixin'
|
8
|
+
require_relative 'plugins/abstract'
|
9
|
+
|
10
|
+
# @since 0.4.0
|
11
|
+
@plugin_registry = Registry.new
|
5
12
|
# @since 0.4.0
|
6
|
-
|
13
|
+
@access_lock = Mutex.new
|
14
|
+
|
15
|
+
class << self
|
16
|
+
# @param plugin_name [Symbol, String]
|
17
|
+
# @return [void]
|
18
|
+
#
|
19
|
+
# @api public
|
20
|
+
# @since 0.4.0
|
21
|
+
def load(plugin_name)
|
22
|
+
thread_safe { plugin_registry[plugin_name].load! }
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [Array<String>]
|
26
|
+
#
|
27
|
+
# @api public
|
28
|
+
# @since 0.4.0
|
29
|
+
def names
|
30
|
+
thread_safe { plugin_registry.names }
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param plugin_name [Symbol, String]
|
34
|
+
# @return [void]
|
35
|
+
#
|
36
|
+
# @api private
|
37
|
+
# @since 0.4.0
|
38
|
+
def register_plugin(plugin_name, plugin_module)
|
39
|
+
thread_safe { plugin_registry[plugin_name] = plugin_module }
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# @return [Qonfig::Plugins::Registry]
|
45
|
+
#
|
46
|
+
# @api private
|
47
|
+
# @since 0.4.0
|
48
|
+
attr_reader :plugin_registry
|
49
|
+
|
50
|
+
# @return [Mutex]
|
51
|
+
#
|
52
|
+
# @api private
|
7
53
|
# @since 0.4.0
|
8
|
-
|
54
|
+
attr_reader :access_lock
|
55
|
+
|
56
|
+
# @return [void]
|
57
|
+
#
|
58
|
+
# @api private
|
9
59
|
# @since 0.4.0
|
10
|
-
|
11
|
-
|
12
|
-
class << self
|
13
|
-
# @param plugin_name [Symbol, String]
|
14
|
-
# @return [void]
|
15
|
-
#
|
16
|
-
# @api public
|
17
|
-
# @since 0.4.0
|
18
|
-
def load(plugin_name)
|
19
|
-
thread_safe { plugin_registry[plugin_name].load! }
|
20
|
-
end
|
21
|
-
|
22
|
-
# @return [Array<String>]
|
23
|
-
#
|
24
|
-
# @api public
|
25
|
-
# @since 0.4.0
|
26
|
-
def names
|
27
|
-
thread_safe { plugin_registry.names }
|
28
|
-
end
|
29
|
-
|
30
|
-
# @param plugin_name [Symbol, String]
|
31
|
-
# @return [void]
|
32
|
-
#
|
33
|
-
# @api private
|
34
|
-
# @since 0.4.0
|
35
|
-
def register_plugin(plugin_name, plugin_module)
|
36
|
-
thread_safe { plugin_registry[plugin_name] = plugin_module }
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
# @return [Qonfig::Plugins::Registry]
|
42
|
-
#
|
43
|
-
# @api private
|
44
|
-
# @since 0.4.0
|
45
|
-
attr_reader :plugin_registry
|
46
|
-
|
47
|
-
# @return [Mutex]
|
48
|
-
#
|
49
|
-
# @api private
|
50
|
-
# @since 0.4.0
|
51
|
-
attr_reader :access_lock
|
52
|
-
|
53
|
-
# @return [void]
|
54
|
-
#
|
55
|
-
# @api private
|
56
|
-
# @since 0.4.0
|
57
|
-
def thread_safe
|
58
|
-
access_lock.synchronize { yield if block_given? }
|
59
|
-
end
|
60
|
+
def thread_safe
|
61
|
+
access_lock.synchronize { yield if block_given? }
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
@@ -1,21 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
# @api private
|
4
|
+
# @since 0.2.0
|
5
|
+
module Qonfig::Settings::Builder
|
6
|
+
class << self
|
7
|
+
# @param commands [Qonfig::CommandSet]
|
8
|
+
# @return [Qonfig::Settings]
|
9
|
+
#
|
5
10
|
# @api private
|
6
11
|
# @since 0.2.0
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# @return [Qonfig::Settings]
|
11
|
-
#
|
12
|
-
# @api private
|
13
|
-
# @since 0.2.0
|
14
|
-
def build(commands)
|
15
|
-
Qonfig::Settings.new.tap do |settings|
|
16
|
-
commands.each { |command| command.call(settings) }
|
17
|
-
end
|
18
|
-
end
|
12
|
+
def build(commands)
|
13
|
+
Qonfig::Settings.new.tap do |settings|
|
14
|
+
commands.each { |command| command.call(settings) }
|
19
15
|
end
|
20
16
|
end
|
21
17
|
end
|