qonfig 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -1
  4. data/.rubocop.yml +1 -1
  5. data/.travis.yml +3 -3
  6. data/CHANGELOG.md +10 -0
  7. data/README.md +146 -1
  8. data/Rakefile +2 -0
  9. data/lib/qonfig/command_set.rb +53 -55
  10. data/lib/qonfig/commands/add_nested_option.rb +36 -40
  11. data/lib/qonfig/commands/add_option.rb +33 -37
  12. data/lib/qonfig/commands/base.rb +9 -13
  13. data/lib/qonfig/commands/compose.rb +29 -33
  14. data/lib/qonfig/commands/expose_yaml.rb +154 -158
  15. data/lib/qonfig/commands/load_from_env.rb +77 -79
  16. data/lib/qonfig/commands/load_from_json.rb +52 -56
  17. data/lib/qonfig/commands/load_from_self.rb +57 -61
  18. data/lib/qonfig/commands/load_from_yaml.rb +54 -58
  19. data/lib/qonfig/commands.rb +15 -0
  20. data/lib/qonfig/configurable.rb +88 -90
  21. data/lib/qonfig/data_set/class_builder.rb +17 -21
  22. data/lib/qonfig/data_set.rb +186 -138
  23. data/lib/qonfig/dsl.rb +106 -108
  24. data/lib/qonfig/{error.rb → exceptions.rb} +13 -1
  25. data/lib/qonfig/loaders/basic.rb +30 -32
  26. data/lib/qonfig/loaders/json.rb +16 -23
  27. data/lib/qonfig/loaders/yaml.rb +16 -23
  28. data/lib/qonfig/loaders.rb +9 -0
  29. data/lib/qonfig/plugins/abstract.rb +7 -11
  30. data/lib/qonfig/plugins/access_mixin.rb +21 -25
  31. data/lib/qonfig/plugins/registry.rb +120 -124
  32. data/lib/qonfig/plugins.rb +56 -54
  33. data/lib/qonfig/settings/builder.rb +10 -14
  34. data/lib/qonfig/settings/key_guard.rb +60 -64
  35. data/lib/qonfig/settings/lock.rb +53 -57
  36. data/lib/qonfig/settings.rb +392 -354
  37. data/lib/qonfig/uploaders/base.rb +18 -0
  38. data/lib/qonfig/uploaders/file.rb +55 -0
  39. data/lib/qonfig/uploaders/json.rb +35 -0
  40. data/lib/qonfig/uploaders/yaml.rb +93 -0
  41. data/lib/qonfig/uploaders.rb +10 -0
  42. data/lib/qonfig/version.rb +1 -1
  43. data/lib/qonfig.rb +4 -21
  44. data/qonfig.gemspec +1 -1
  45. metadata +13 -6
@@ -1,75 +1,71 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Qonfig
4
- class Settings
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
- class KeyGuard
8
- class << self
9
- # @param key [String, Symbol, Object]
10
- # @return [void]
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
- # @return [String, Symbol, Object]
23
- #
24
- # @api private
25
- # @sicne 0.2.0
26
- attr_reader :key
20
+ # @return [String, Symbol, Object]
21
+ #
22
+ # @api private
23
+ # @sicne 0.2.0
24
+ attr_reader :key
27
25
 
28
- # @param key [String, Symbol, Object]
29
- #
30
- # @api private
31
- # @since 0.2.0
32
- def initialize(key)
33
- @key = key
34
- end
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
- # @return [void]
37
- #
38
- # @raise [Qonfig::ArgumentError]
39
- # @raise [Qonfig::CoreMethodIntersectionError]
40
- #
41
- # @api private
42
- # @since 0.2.0
43
- def prevent_incomparabilities!
44
- prevent_incompatible_key_type!
45
- prevent_core_method_intersection!
46
- end
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
- # @return [void]
49
- #
50
- # @raise [Qonfig::ArgumentError]
51
- #
52
- # @api private
53
- # @since 0.2.0
54
- def prevent_incompatible_key_type!
55
- raise(
56
- Qonfig::ArgumentError,
57
- 'Setting key should be a symbol or a string!'
58
- ) unless key.is_a?(Symbol) || key.is_a?(String)
59
- end
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
- # @return [void]
62
- #
63
- # @raise [Qonfig::CoreMethodIntersectionError]
64
- #
65
- # @api private
66
- # @since 0.2.0
67
- def prevent_core_method_intersection!
68
- raise(
69
- Qonfig::CoreMethodIntersectionError,
70
- "<#{key}> key can not be used since this is a private core method"
71
- ) if Qonfig::Settings::CORE_METHODS.include?(key.to_s)
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
@@ -1,64 +1,60 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Qonfig
4
- class Settings
5
- # @api private
6
- # @since 0.2.0
7
- class Lock
8
- # @api private
9
- # @since 0.2.0
10
- def initialize
11
- @definition_lock = Mutex.new
12
- @access_lock = Mutex.new
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
- # @return [Mutex]
46
- #
47
- # @api private
48
- # @since 0.2.0
49
- attr_reader :definition_lock
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
- # @return [Mutex]
52
- #
53
- # @api private
54
- # @since 0.2.0
55
- attr_reader :access_lock
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
- # @return [Mutex]
58
- #
59
- # @api private
60
- # @since 0.2.0
61
- attr_reader :merge_lock
62
- end
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