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
@@ -1,75 +1,71 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
# @api private
|
4
|
+
# @since 0.2.0
|
5
|
+
class Qonfig::Settings::KeyGuard
|
6
|
+
class << self
|
7
|
+
# @param key [String, Symbol, Object]
|
8
|
+
# @return [void]
|
9
|
+
#
|
10
|
+
# @raise [Qonfig::ArgumentError]
|
11
|
+
# @raise [Qonfig::CoreMethodIntersectionError]
|
12
|
+
#
|
5
13
|
# @api private
|
6
14
|
# @since 0.2.0
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
# @raise [Qonfig::ArgumentError]
|
13
|
-
# @raise [Qonfig::CoreMethodIntersectionError]
|
14
|
-
#
|
15
|
-
# @api private
|
16
|
-
# @since 0.2.0
|
17
|
-
def prevent_incomparabilities!(key)
|
18
|
-
new(key).prevent_incomparabilities!
|
19
|
-
end
|
20
|
-
end
|
15
|
+
def prevent_incomparabilities!(key)
|
16
|
+
new(key).prevent_incomparabilities!
|
17
|
+
end
|
18
|
+
end
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
# @return [String, Symbol, Object]
|
21
|
+
#
|
22
|
+
# @api private
|
23
|
+
# @sicne 0.2.0
|
24
|
+
attr_reader :key
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
# @param key [String, Symbol, Object]
|
27
|
+
#
|
28
|
+
# @api private
|
29
|
+
# @since 0.2.0
|
30
|
+
def initialize(key)
|
31
|
+
@key = key
|
32
|
+
end
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
34
|
+
# @return [void]
|
35
|
+
#
|
36
|
+
# @raise [Qonfig::ArgumentError]
|
37
|
+
# @raise [Qonfig::CoreMethodIntersectionError]
|
38
|
+
#
|
39
|
+
# @api private
|
40
|
+
# @since 0.2.0
|
41
|
+
def prevent_incomparabilities!
|
42
|
+
prevent_incompatible_key_type!
|
43
|
+
prevent_core_method_intersection!
|
44
|
+
end
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
46
|
+
# @return [void]
|
47
|
+
#
|
48
|
+
# @raise [Qonfig::ArgumentError]
|
49
|
+
#
|
50
|
+
# @api private
|
51
|
+
# @since 0.2.0
|
52
|
+
def prevent_incompatible_key_type!
|
53
|
+
raise(
|
54
|
+
Qonfig::ArgumentError,
|
55
|
+
'Setting key should be a symbol or a string!'
|
56
|
+
) unless key.is_a?(Symbol) || key.is_a?(String)
|
57
|
+
end
|
60
58
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
end
|
59
|
+
# @return [void]
|
60
|
+
#
|
61
|
+
# @raise [Qonfig::CoreMethodIntersectionError]
|
62
|
+
#
|
63
|
+
# @api private
|
64
|
+
# @since 0.2.0
|
65
|
+
def prevent_core_method_intersection!
|
66
|
+
raise(
|
67
|
+
Qonfig::CoreMethodIntersectionError,
|
68
|
+
"<#{key}> key can not be used since this is a private core method"
|
69
|
+
) if Qonfig::Settings::CORE_METHODS.include?(key.to_s)
|
74
70
|
end
|
75
71
|
end
|
data/lib/qonfig/settings/lock.rb
CHANGED
@@ -1,64 +1,60 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@merge_lock = Mutex.new
|
14
|
-
end
|
15
|
-
|
16
|
-
# @param instructions [Proc]
|
17
|
-
# @return [Object]
|
18
|
-
#
|
19
|
-
# @api private
|
20
|
-
# @since 0.2.0
|
21
|
-
def thread_safe_definition(&instructions)
|
22
|
-
definition_lock.synchronize(&instructions)
|
23
|
-
end
|
24
|
-
|
25
|
-
# @param instructions [Proc]
|
26
|
-
# @return [Object]
|
27
|
-
#
|
28
|
-
# @api private
|
29
|
-
# @since 0.2.0
|
30
|
-
def thread_safe_access(&instructions)
|
31
|
-
access_lock.synchronize(&instructions)
|
32
|
-
end
|
33
|
-
|
34
|
-
# @param instructions [Proc]
|
35
|
-
# @return [Object]
|
36
|
-
#
|
37
|
-
# @api private
|
38
|
-
# @since 0.2.0
|
39
|
-
def thread_safe_merge(&instructions)
|
40
|
-
merge_lock.synchronize(&instructions)
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
3
|
+
# @api private
|
4
|
+
# @since 0.2.0
|
5
|
+
class Qonfig::Settings::Lock
|
6
|
+
# @api private
|
7
|
+
# @since 0.2.0
|
8
|
+
def initialize
|
9
|
+
@definition_lock = Mutex.new
|
10
|
+
@access_lock = Mutex.new
|
11
|
+
@merge_lock = Mutex.new
|
12
|
+
end
|
44
13
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
14
|
+
# @param instructions [Proc]
|
15
|
+
# @return [Object]
|
16
|
+
#
|
17
|
+
# @api private
|
18
|
+
# @since 0.2.0
|
19
|
+
def thread_safe_definition(&instructions)
|
20
|
+
definition_lock.synchronize(&instructions)
|
21
|
+
end
|
50
22
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
23
|
+
# @param instructions [Proc]
|
24
|
+
# @return [Object]
|
25
|
+
#
|
26
|
+
# @api private
|
27
|
+
# @since 0.2.0
|
28
|
+
def thread_safe_access(&instructions)
|
29
|
+
access_lock.synchronize(&instructions)
|
30
|
+
end
|
56
31
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
32
|
+
# @param instructions [Proc]
|
33
|
+
# @return [Object]
|
34
|
+
#
|
35
|
+
# @api private
|
36
|
+
# @since 0.2.0
|
37
|
+
def thread_safe_merge(&instructions)
|
38
|
+
merge_lock.synchronize(&instructions)
|
63
39
|
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
# @return [Mutex]
|
44
|
+
#
|
45
|
+
# @api private
|
46
|
+
# @since 0.2.0
|
47
|
+
attr_reader :definition_lock
|
48
|
+
|
49
|
+
# @return [Mutex]
|
50
|
+
#
|
51
|
+
# @api private
|
52
|
+
# @since 0.2.0
|
53
|
+
attr_reader :access_lock
|
54
|
+
|
55
|
+
# @return [Mutex]
|
56
|
+
#
|
57
|
+
# @api private
|
58
|
+
# @since 0.2.0
|
59
|
+
attr_reader :merge_lock
|
64
60
|
end
|