qonfig 0.21.0 → 0.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.travis.yml +23 -20
  4. data/CHANGELOG.md +58 -2
  5. data/LICENSE.txt +1 -1
  6. data/README.md +124 -10
  7. data/Rakefile +0 -1
  8. data/bin/rspec +1 -0
  9. data/gemfiles/with_external_deps.gemfile +2 -0
  10. data/lib/qonfig.rb +4 -0
  11. data/lib/qonfig/commands/definition/expose_json.rb +2 -2
  12. data/lib/qonfig/commands/definition/expose_yaml.rb +2 -2
  13. data/lib/qonfig/commands/definition/load_from_json.rb +2 -2
  14. data/lib/qonfig/commands/definition/load_from_yaml.rb +2 -2
  15. data/lib/qonfig/commands/instantiation/values_file.rb +13 -4
  16. data/lib/qonfig/data_set.rb +13 -9
  17. data/lib/qonfig/dsl.rb +7 -7
  18. data/lib/qonfig/plugins.rb +1 -0
  19. data/lib/qonfig/plugins/pretty_print.rb +8 -1
  20. data/lib/qonfig/plugins/pretty_print/requirements.rb +3 -0
  21. data/lib/qonfig/plugins/pretty_print/ruby_2_7_basic_object_pp_patch.rb +44 -0
  22. data/lib/qonfig/plugins/toml/commands/definition/expose_toml.rb +4 -4
  23. data/lib/qonfig/plugins/toml/commands/definition/load_from_toml.rb +1 -1
  24. data/lib/qonfig/plugins/toml/data_set.rb +2 -2
  25. data/lib/qonfig/plugins/toml/dsl.rb +2 -2
  26. data/lib/qonfig/plugins/vault.rb +24 -0
  27. data/lib/qonfig/plugins/vault/commands/definition/expose_vault.rb +142 -0
  28. data/lib/qonfig/plugins/vault/commands/definition/load_from_vault.rb +53 -0
  29. data/lib/qonfig/plugins/vault/dsl.rb +35 -0
  30. data/lib/qonfig/plugins/vault/errors.rb +9 -0
  31. data/lib/qonfig/plugins/vault/loaders/vault.rb +73 -0
  32. data/lib/qonfig/settings.rb +78 -21
  33. data/lib/qonfig/settings/key_matcher.rb +2 -0
  34. data/lib/qonfig/uploaders/file.rb +2 -2
  35. data/lib/qonfig/uploaders/yaml.rb +1 -1
  36. data/lib/qonfig/version.rb +1 -1
  37. data/qonfig.gemspec +5 -6
  38. metadata +20 -26
@@ -18,7 +18,7 @@ class Qonfig::Commands::Definition::ExposeJSON < Qonfig::Commands::Base
18
18
  # @since 0.14.0
19
19
  EMPTY_JSON_DATA = {}.freeze
20
20
 
21
- # @return [String]
21
+ # @return [String, Pathname]
22
22
  #
23
23
  # @api private
24
24
  # @since 0.14.0
@@ -42,7 +42,7 @@ class Qonfig::Commands::Definition::ExposeJSON < Qonfig::Commands::Base
42
42
  # @since 0.14.0
43
43
  attr_reader :env
44
44
 
45
- # @param file_path [String]
45
+ # @param file_path [String, Pathname]
46
46
  # @option strict [Boolean]
47
47
  # @option via [Symbol]
48
48
  # @option env [String, Symbol]
@@ -18,7 +18,7 @@ class Qonfig::Commands::Definition::ExposeYAML < Qonfig::Commands::Base
18
18
  # @since 0.7.0
19
19
  EMPTY_YAML_DATA = {}.freeze
20
20
 
21
- # @return [String]
21
+ # @return [String, Pathname]
22
22
  #
23
23
  # @api private
24
24
  # @since 0.7.0
@@ -42,7 +42,7 @@ class Qonfig::Commands::Definition::ExposeYAML < Qonfig::Commands::Base
42
42
  # @since 0.7.0
43
43
  attr_reader :env
44
44
 
45
- # @param file_path [String]
45
+ # @param file_path [String, Pathname]
46
46
  # @option strict [Boolean]
47
47
  # @option via [Symbol]
48
48
  # @option env [String, Symbol]
@@ -6,7 +6,7 @@ class Qonfig::Commands::Definition::LoadFromJSON < Qonfig::Commands::Base
6
6
  # @since 0.19.0
7
7
  self.inheritable = true
8
8
 
9
- # @return [String]
9
+ # @return [String, Pathname]
10
10
  #
11
11
  # @api private
12
12
  # @since 0.5.0
@@ -18,7 +18,7 @@ class Qonfig::Commands::Definition::LoadFromJSON < Qonfig::Commands::Base
18
18
  # @sicne 0.5.0
19
19
  attr_reader :strict
20
20
 
21
- # @param file_path [String]
21
+ # @param file_path [String, Pathname]
22
22
  # @option strict [Boolean]
23
23
  #
24
24
  # @api private
@@ -6,7 +6,7 @@ class Qonfig::Commands::Definition::LoadFromYAML < Qonfig::Commands::Base
6
6
  # @since 0.19.0
7
7
  self.inheritable = true
8
8
 
9
- # @return [String]
9
+ # @return [String, Pathname]
10
10
  #
11
11
  # @api private
12
12
  # @since 0.2.0
@@ -18,7 +18,7 @@ class Qonfig::Commands::Definition::LoadFromYAML < Qonfig::Commands::Base
18
18
  # @since 0.2.0
19
19
  attr_reader :strict
20
20
 
21
- # @param file_path [String]
21
+ # @param file_path [String, Pathname]
22
22
  # @option strict [Boolean]
23
23
  #
24
24
  # @api private
@@ -30,10 +30,11 @@ class Qonfig::Commands::Instantiation::ValuesFile < Qonfig::Commands::Base
30
30
  # @since 0.17.0
31
31
  DEFAULT_FORMAT = :dynamic
32
32
 
33
- # @return [String, Symbol]
33
+ # @return [String, Symbol, Pathname]
34
34
  #
35
35
  # @api private
36
36
  # @since 0.17.0
37
+ # @version 0.22.0
37
38
  attr_reader :file_path
38
39
 
39
40
  # @return [String]
@@ -60,7 +61,7 @@ class Qonfig::Commands::Instantiation::ValuesFile < Qonfig::Commands::Base
60
61
  # @since 0.17.0
61
62
  attr_reader :expose
62
63
 
63
- # @param file_path [String, Symbol]
64
+ # @param file_path [String, Symbol, Pathname]
64
65
  # @param caller_location [String]
65
66
  # @option format [String, Symbol]
66
67
  # @option strict [Boolean]
@@ -69,6 +70,7 @@ class Qonfig::Commands::Instantiation::ValuesFile < Qonfig::Commands::Base
69
70
  #
70
71
  # @api private
71
72
  # @since 0.17.0
73
+ # @version 0.22.0
72
74
  def initialize(
73
75
  file_path,
74
76
  caller_location,
@@ -140,7 +142,7 @@ class Qonfig::Commands::Instantiation::ValuesFile < Qonfig::Commands::Base
140
142
  raise(error) if strict
141
143
  end
142
144
 
143
- # @param file_path [String, Symbol]
145
+ # @param file_path [String, Symbol, Pathname]
144
146
  # @param format [String, Symbol]
145
147
  # @param strict [Boolean]
146
148
  # @param expose [NilClass, String, Symbol]
@@ -151,8 +153,14 @@ class Qonfig::Commands::Instantiation::ValuesFile < Qonfig::Commands::Base
151
153
  #
152
154
  # @api private
153
155
  # @since 0.17.0
156
+ # @version 0.22.0
157
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
154
158
  def prevent_incompatible_attributes!(file_path, format, strict, expose)
155
- unless file_path.is_a?(String) || file_path == SELF_LOCATED_FILE_DEFINITION
159
+ unless (
160
+ file_path.is_a?(String) ||
161
+ file_path.is_a?(Pathname) ||
162
+ file_path == SELF_LOCATED_FILE_DEFINITION
163
+ )
156
164
  raise Qonfig::ArgumentError, 'Incorrect file path'
157
165
  end
158
166
 
@@ -171,4 +179,5 @@ class Qonfig::Commands::Instantiation::ValuesFile < Qonfig::Commands::Base
171
179
  raise Qonfig::ArgumentError, ':strict should be a type of boolean'
172
180
  end
173
181
  end
182
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
174
183
  end
@@ -97,7 +97,7 @@ class Qonfig::DataSet # rubocop:disable Metrics/ClassLength
97
97
  end
98
98
  end
99
99
 
100
- # @param file_path [String, Symbol]
100
+ # @param file_path [String, Symbol, Pathname]
101
101
  # @option format [String, Symbol]
102
102
  # @option strict [Boolean]
103
103
  # @option expose [NilClass, String, Symbol] Environment key
@@ -108,7 +108,7 @@ class Qonfig::DataSet # rubocop:disable Metrics/ClassLength
108
108
  #
109
109
  # @api public
110
110
  # @since 0.17.0
111
- # @version 0.21.0
111
+ # @version 0.22.0
112
112
  def load_from_file(file_path, format: :dynamic, strict: true, expose: nil, &configurations)
113
113
  thread_safe_access do
114
114
  load_setting_values_from_file(
@@ -117,7 +117,7 @@ class Qonfig::DataSet # rubocop:disable Metrics/ClassLength
117
117
  end
118
118
  end
119
119
 
120
- # @param file_path [String]
120
+ # @param file_path [String, Symbol, Pathname]
121
121
  # @option strict [Boolean]
122
122
  # @option expose [NilClass, String, Symbol] Environment key
123
123
  # @param configurations [Block]
@@ -127,12 +127,12 @@ class Qonfig::DataSet # rubocop:disable Metrics/ClassLength
127
127
  #
128
128
  # @api public
129
129
  # @since 0.17.0
130
- # @version 0.21.0
130
+ # @version 0.22.0
131
131
  def load_from_yaml(file_path, strict: true, expose: nil, &configurations)
132
132
  load_from_file(file_path, format: :yml, strict: strict, expose: expose, &configurations)
133
133
  end
134
134
 
135
- # @param file_path [String]
135
+ # @param file_path [String, Symbol, Pathname]
136
136
  # @option strict [Boolean]
137
137
  # @option expose [NilClass, String, Symbol] Environment key
138
138
  # @param configurations [Block]
@@ -142,7 +142,7 @@ class Qonfig::DataSet # rubocop:disable Metrics/ClassLength
142
142
  #
143
143
  # @api public
144
144
  # @since 0.17.0
145
- # @version 0.21.0
145
+ # @version 0.22.0
146
146
  def load_from_json(file_path, strict: true, expose: nil, &configurations)
147
147
  load_from_file(file_path, format: :json, strict: strict, expose: expose, &configurations)
148
148
  end
@@ -184,6 +184,7 @@ class Qonfig::DataSet # rubocop:disable Metrics/ClassLength
184
184
  end
185
185
  end
186
186
 
187
+ # @option dot_style [Boolean]
187
188
  # @option key_transformer [Proc]
188
189
  # @option value_transformer [Proc]
189
190
  # @return [Hash]
@@ -191,11 +192,13 @@ class Qonfig::DataSet # rubocop:disable Metrics/ClassLength
191
192
  # @api public
192
193
  # @since 0.1.0
193
194
  def to_h(
195
+ dot_style: Qonfig::Settings::REPRESENT_HASH_IN_DOT_STYLE,
194
196
  key_transformer: Qonfig::Settings::BASIC_SETTING_KEY_TRANSFORMER,
195
197
  value_transformer: Qonfig::Settings::BASIC_SETTING_VALUE_TRANSFORMER
196
198
  )
197
199
  thread_safe_access do
198
200
  settings.__to_hash__(
201
+ dot_notation: dot_style,
199
202
  transform_key: key_transformer,
200
203
  transform_value: value_transformer
201
204
  )
@@ -203,7 +206,7 @@ class Qonfig::DataSet # rubocop:disable Metrics/ClassLength
203
206
  end
204
207
  alias_method :to_hash, :to_h
205
208
 
206
- # @option path [String]
209
+ # @option path [String, Pathname]
207
210
  # @option options [Hash<Symbol|String,Any>] Native (ruby-stdlib) ::JSON#generate attributes
208
211
  # @param value_processor [Block]
209
212
  # @return [void]
@@ -217,7 +220,7 @@ class Qonfig::DataSet # rubocop:disable Metrics/ClassLength
217
220
  end
218
221
  alias_method :dump_to_json, :save_to_json
219
222
 
220
- # @option path [String]
223
+ # @option path [String, Pathname]
221
224
  # @option symbolize_keys [Boolean]
222
225
  # @option options [Hash<Symbol|String,Any>] Native (ruby-stdlib) ::YAML#dump attributes
223
226
  # @param value_processor [Block]
@@ -513,7 +516,7 @@ class Qonfig::DataSet # rubocop:disable Metrics/ClassLength
513
516
  apply_settings(settings_map, &configurations)
514
517
  end
515
518
 
516
- # @param file_path [String, Symbol]
519
+ # @param file_path [String, Symbol, Pathname]
517
520
  # @option format [String, Symbol]
518
521
  # @option strict [Boolean]
519
522
  # @option expose [NilClass, String, Symbol]
@@ -525,6 +528,7 @@ class Qonfig::DataSet # rubocop:disable Metrics/ClassLength
525
528
  #
526
529
  # @api private
527
530
  # @since 0.17.0
531
+ # @version 0.22.0
528
532
  def load_setting_values_from_file(
529
533
  file_path,
530
534
  format: :dynamic,
@@ -15,7 +15,7 @@ module Qonfig::DSL # rubocop:disable Metrics/ModuleLength
15
15
  # @api private
16
16
  # @since 0.1.0
17
17
  # @version 0.20.0
18
- # rubocop:disable Metrics/LineLength, Metrics/AbcSize
18
+ # rubocop:disable Layout/LineLength, Metrics/AbcSize
19
19
  def extended(child_klass)
20
20
  child_klass.instance_variable_set(:@definition_commands, Qonfig::CommandSet.new)
21
21
  child_klass.instance_variable_set(:@instance_commands, Qonfig::CommandSet.new)
@@ -33,7 +33,7 @@ module Qonfig::DSL # rubocop:disable Metrics/ModuleLength
33
33
  end
34
34
  end)
35
35
  end
36
- # rubocop:enable Metrics/LineLength, Metrics/AbcSize
36
+ # rubocop:enable Layout/LineLength, Metrics/AbcSize
37
37
  end
38
38
 
39
39
  # @return [Qonfig::CommandSet]
@@ -154,7 +154,7 @@ module Qonfig::DSL # rubocop:disable Metrics/ModuleLength
154
154
  definition_commands << Qonfig::Commands::Definition::Compose.new(data_set_klass)
155
155
  end
156
156
 
157
- # @param file_path [String]
157
+ # @param file_path [String, Pathname]
158
158
  # @option strict [Boolean]
159
159
  # @return [void]
160
160
  #
@@ -200,7 +200,7 @@ module Qonfig::DSL # rubocop:disable Metrics/ModuleLength
200
200
  )
201
201
  end
202
202
 
203
- # @param file_path [String]
203
+ # @param file_path [String, Pathname]
204
204
  # @option strict [Boolean]
205
205
  # @return [void]
206
206
  #
@@ -212,7 +212,7 @@ module Qonfig::DSL # rubocop:disable Metrics/ModuleLength
212
212
  definition_commands << Qonfig::Commands::Definition::LoadFromJSON.new(file_path, strict: strict)
213
213
  end
214
214
 
215
- # @param file_path [String]
215
+ # @param file_path [String, Pathname]
216
216
  # @option strict [Boolean]
217
217
  # @option via [Symbol]
218
218
  # @option env [Symbol, String]
@@ -228,7 +228,7 @@ module Qonfig::DSL # rubocop:disable Metrics/ModuleLength
228
228
  )
229
229
  end
230
230
 
231
- # @param file_path [String]
231
+ # @param file_path [String, Pathname]
232
232
  # @option strict [Boolean]
233
233
  # @option via [Symbol]
234
234
  # @option env [Symbol, String]
@@ -261,7 +261,7 @@ module Qonfig::DSL # rubocop:disable Metrics/ModuleLength
261
261
  )
262
262
  end
263
263
 
264
- # @param file_path [String]
264
+ # @param file_path [String, Pathname]
265
265
  # @option format [String, Symbol]
266
266
  # @option strict [Boolean]
267
267
  # @option expose [NilClass, String, Symbol] Environment key
@@ -8,6 +8,7 @@ module Qonfig::Plugins
8
8
  require_relative 'plugins/abstract'
9
9
  require_relative 'plugins/toml'
10
10
  require_relative 'plugins/pretty_print'
11
+ require_relative 'plugins/vault'
11
12
 
12
13
  # @since 0.4.0
13
14
  @plugin_registry = Registry.new
@@ -8,8 +8,15 @@ class Qonfig::Plugins::PrettyPrint < Qonfig::Plugins::Abstract
8
8
  #
9
9
  # @api private
10
10
  # @since 0.19.0
11
- # @version 0.21.0
11
+ # @version 0.24.0
12
12
  def install!
13
+ # :nocov:
14
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
15
+ require_relative 'pretty_print/ruby_2_7_basic_object_pp_patch'
16
+ end
17
+ # :nocov:
18
+
19
+ require_relative 'pretty_print/requirements'
13
20
  require_relative 'pretty_print/mixin'
14
21
  require_relative 'pretty_print/data_set'
15
22
  require_relative 'pretty_print/settings'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pp'
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # NOTE: why not `.prepend` ?
4
+ # `prepend` in this case works incorrectly and sometimes this patch can not be correctly
5
+ # injected to the original module and it's children ancestors (Ruby-specific behaviour of
6
+ # module including and prepending).
7
+
8
+ # @api public
9
+ # @since 0.24.0
10
+ module PP::PPMethods
11
+ # :nocov:
12
+ def pp(obj)
13
+ # If obj is a Delegator then use the object being delegated to for cycle
14
+ # detection
15
+
16
+ # NOTE: --- PATCH ---
17
+ if defined?(::Delegator) and (
18
+ begin
19
+ (class << obj; self; end) <= ::Delegator # patch
20
+ rescue ::TypeError
21
+ obj.is_a?(::Delegator)
22
+ end
23
+ )
24
+ obj = obj.__getobj__
25
+ end # instead of: obj = obj.__getobj__ if defined?(::Delegator) and obj.is_a?(::Delegator)
26
+ # NOTE:
27
+ # Old implementation can not be used with BasicObject instances
28
+ # (with Qonfig::Compacted in our case)
29
+ # NOTE: --- PATCH ---
30
+
31
+ if check_inspect_key(obj)
32
+ group { obj.pretty_print_cycle self }
33
+ return
34
+ end
35
+
36
+ begin
37
+ push_inspect_key(obj)
38
+ group { obj.pretty_print self }
39
+ ensure
40
+ pop_inspect_key(obj) unless PP.sharing_detection
41
+ end
42
+ end
43
+ # :nocov:
44
+ end
@@ -19,7 +19,7 @@ class Qonfig::Commands::Definition::ExposeTOML < Qonfig::Commands::Base
19
19
  # @since 0.12.0
20
20
  EMPTY_TOML_DATA = {}.freeze
21
21
 
22
- # @return [String]
22
+ # @return [String, Pathname]
23
23
  #
24
24
  # @api private
25
25
  # @since 0.12.0
@@ -101,7 +101,7 @@ class Qonfig::Commands::Definition::ExposeTOML < Qonfig::Commands::Base
101
101
  realfile = dirname.join(envfile).to_s
102
102
 
103
103
  toml_data = load_toml_data(realfile)
104
- toml_based_settings = builde_data_set_klass(toml_data).new.settings
104
+ toml_based_settings = build_data_set_klass(toml_data).new.settings
105
105
 
106
106
  settings.__append_settings__(toml_based_settings)
107
107
  end
@@ -125,7 +125,7 @@ class Qonfig::Commands::Definition::ExposeTOML < Qonfig::Commands::Base
125
125
  "#{file_path} file does not contain settings with <#{env}> environment key!"
126
126
  ) unless toml_data_slice
127
127
 
128
- toml_based_settings = builde_data_set_klass(toml_data_slice).new.settings
128
+ toml_based_settings = build_data_set_klass(toml_data_slice).new.settings
129
129
 
130
130
  settings.__append_settings__(toml_based_settings)
131
131
  end
@@ -145,7 +145,7 @@ class Qonfig::Commands::Definition::ExposeTOML < Qonfig::Commands::Base
145
145
  #
146
146
  # @api private
147
147
  # @since 0.12.0
148
- def builde_data_set_klass(toml_data)
148
+ def build_data_set_klass(toml_data)
149
149
  Qonfig::DataSet::ClassBuilder.build_from_hash(toml_data)
150
150
  end
151
151
  end
@@ -7,7 +7,7 @@ class Qonfig::Commands::Definition::LoadFromTOML < Qonfig::Commands::Base
7
7
  # @since 0.20.0
8
8
  self.inheritable = true
9
9
 
10
- # @return [String]
10
+ # @return [String, Pathname]
11
11
  #
12
12
  # @api private
13
13
  # @since 0.12.0
@@ -3,7 +3,7 @@
3
3
  # @api public
4
4
  # @since 0.12.0
5
5
  class Qonfig::DataSet
6
- # @option path [String]
6
+ # @option path [String, Pathname]
7
7
  # @option options [Hash<Symbol,Any>] Nothing, just for compatability and consistency
8
8
  # @param value_processor [Block]
9
9
  # @return [void]
@@ -17,7 +17,7 @@ class Qonfig::DataSet
17
17
  end
18
18
  alias_method :dump_to_toml, :save_to_toml
19
19
 
20
- # @param file_path [String]
20
+ # @param file_path [String, Pathmame]
21
21
  # @option strict [Boolean]
22
22
  # @option expose [NilClass, String, Symbol] Environment key
23
23
  # @param configuration [Block]
@@ -3,7 +3,7 @@
3
3
  # @api private
4
4
  # @since 0.12.0
5
5
  module Qonfig::DSL
6
- # @param file_path [String]
6
+ # @param file_path [String, Pathname]
7
7
  # @option strict [Boolean]
8
8
  # @return [void]
9
9
  #
@@ -18,7 +18,7 @@ module Qonfig::DSL
18
18
  )
19
19
  end
20
20
 
21
- # @param file_path [String]
21
+ # @param file_path [String, Pathname]
22
22
  # @option strict [Boolean]
23
23
  # @option via [Symbol]
24
24
  # @option env [Symbol, String]