rdm 0.4.14.2 → 0.4.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile.lock +26 -19
  3. data/bin/rdm +10 -10
  4. data/example/Rdm.packages +1 -17
  5. data/example/config/app.yml +6 -0
  6. data/example/infrastructure/repository/Package.rb +0 -1
  7. data/example/infrastructure/repository/fixture.txt +1 -0
  8. data/lib/rdm.rb +14 -7
  9. data/lib/rdm/errors.rb +3 -0
  10. data/lib/rdm/gen/init.rb +0 -4
  11. data/lib/rdm/package.rb +18 -9
  12. data/lib/rdm/package_importer.rb +4 -18
  13. data/lib/rdm/package_parser.rb +1 -0
  14. data/lib/rdm/packages/compiler_service.rb +1 -7
  15. data/lib/rdm/settings.rb +10 -21
  16. data/lib/rdm/source.rb +1 -18
  17. data/lib/rdm/source_parser.rb +2 -45
  18. data/lib/rdm/templates/init/Rdm.packages +0 -12
  19. data/lib/rdm/utils/ostruct_utils.rb +12 -0
  20. data/lib/rdm/version.rb +1 -1
  21. data/lib/rdm/yml_config/config_caster.rb +32 -0
  22. data/lib/rdm/yml_config/config_manager.rb +39 -0
  23. data/lib/rdm/yml_config/config_validator.rb +51 -0
  24. data/lib/rdm/yml_config/env_config.rb +46 -0
  25. data/lib/rdm/yml_config/env_config_dsl.rb +92 -0
  26. data/lib/rdm/yml_config/validate_config.rb +13 -0
  27. data/rdm.gemspec +3 -0
  28. data/spec/fixtures/SampleSource.rb +2 -4
  29. data/spec/fixtures/app.yml +17 -0
  30. data/spec/rdm/cli/gen_package_spec.rb +0 -2
  31. data/spec/rdm/gen/init_spec.rb +0 -12
  32. data/spec/rdm/gen/package_spec.rb +1 -0
  33. data/spec/rdm/package_importer_spec.rb +34 -2
  34. data/spec/rdm/rdm_spec.rb +1 -1
  35. data/spec/rdm/source_parser_spec.rb +0 -59
  36. data/spec/rdm/yml_config/config_caster_spec.rb +64 -0
  37. data/spec/rdm/yml_config/config_manager_spec.rb +7 -0
  38. data/spec/rdm/yml_config/config_validator_spec.rb +190 -0
  39. data/spec/rdm/yml_config/env_config_dsl_spec.rb +123 -0
  40. data/spec/spec_helper.rb +1 -0
  41. metadata +69 -34
  42. data/example/.rdm/templates/configs/<%=config_path%> +0 -2
  43. data/example/.rdm/templates/configs/<%=role_config_path%> +0 -2
  44. data/example/configs/app/default.yml +0 -2
  45. data/example/configs/app/production.yml +0 -2
  46. data/example/configs/database/default.yml +0 -3
  47. data/example/env_files/development.env +0 -3
  48. data/example/env_files/production.env +0 -5
  49. data/example/env_files/test.env +0 -3
  50. data/lib/rdm/cli/config.rb +0 -31
  51. data/lib/rdm/config.rb +0 -11
  52. data/lib/rdm/config_locals.rb +0 -11
  53. data/lib/rdm/config_manager.rb +0 -68
  54. data/lib/rdm/config_scope.rb +0 -23
  55. data/lib/rdm/gen/config.rb +0 -59
  56. data/lib/rdm/templates/configs/<%=config_path%> +0 -2
  57. data/lib/rdm/templates/configs/<%=role_config_path%> +0 -2
  58. data/lib/rdm/templates/init/env_files/development.env +0 -3
  59. data/lib/rdm/templates/init/env_files/production.env +0 -3
  60. data/lib/rdm/templates/init/env_files/test.env +0 -3
  61. data/spec/fixtures/config.yml +0 -2
  62. data/spec/rdm/config_manager_spec.rb +0 -136
  63. data/spec/rdm/gen/config_spec.rb +0 -31
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rdm::EnvConfigDSL do
4
+ subject { described_class.new }
5
+ let(:env_context) {
6
+ Proc.new do
7
+ string :url, optional: true do
8
+ length({ min: 4, max: 7, equal_to: 2 })
9
+ end
10
+
11
+ array :connections, each: :string, default: [4] do
12
+ size({ min: 0, max: 20})
13
+ end
14
+
15
+ hash :log_level do
16
+ symbol :output do
17
+ inclusion({ in: [:warn, :debug, :fatal, :error, :info] })
18
+ end
19
+
20
+ integer :level
21
+ end
22
+
23
+ array :some_array, each: :hash do
24
+ string :key do
25
+ length({ min: 4, max: 10 })
26
+ end
27
+
28
+ string :one_more_key, optional: true
29
+ end
30
+ end
31
+ }
32
+
33
+ it 'handle dsl' do
34
+ subject.instance_exec(&env_context)
35
+
36
+ expect(subject.data.first).to be_a(Rdm::EnvConfig)
37
+ expect(subject.data.map(&:to_hash)).to match(
38
+ [
39
+ {
40
+ name: :url,
41
+ type: :string,
42
+ optional: true,
43
+ validates: {
44
+ length: {
45
+ min: 4,
46
+ max: 7,
47
+ equal_to: 2
48
+ }
49
+ }
50
+ },
51
+ {
52
+ name: :connections,
53
+ type: :array,
54
+ optional: false,
55
+ default: [4],
56
+ children: [
57
+ {
58
+ type: :string,
59
+ optional: false,
60
+ validates: {
61
+ size: {
62
+ min: 0,
63
+ max: 20
64
+ }
65
+ }
66
+ }
67
+ ]
68
+ },
69
+ {
70
+ name: :log_level,
71
+ type: :hash,
72
+ optional: false,
73
+ children: [
74
+ {
75
+ name: :output,
76
+ type: :symbol,
77
+ optional: false,
78
+ validates: {
79
+ inclusion: {
80
+ in: [:warn, :debug, :fatal, :error, :info]
81
+ }
82
+ }
83
+ },
84
+ {
85
+ name: :level,
86
+ type: :integer,
87
+ optional: false
88
+ }
89
+ ]
90
+ },
91
+ {
92
+ name: :some_array,
93
+ type: :array,
94
+ optional: false,
95
+ children: [
96
+ {
97
+ type: :hash,
98
+ optional: false,
99
+ children: [
100
+ {
101
+ name: :key,
102
+ type: :string,
103
+ optional: false,
104
+ validates: {
105
+ length: {
106
+ min: 4,
107
+ max: 10
108
+ }
109
+ }
110
+ },
111
+ {
112
+ name: :one_more_key,
113
+ type: :string,
114
+ optional: true
115
+ }
116
+ ]
117
+ }
118
+ ]
119
+ }
120
+ ]
121
+ )
122
+ end
123
+ end
@@ -26,6 +26,7 @@ end
26
26
 
27
27
  Rdm.setup do
28
28
  silence_missing_package_file true
29
+ config_path File.join(__dir__, 'fixtures', 'app.yml')
29
30
  end
30
31
 
31
32
  RSpec.configure do |config|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.14.2
4
+ version: 0.4.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Droid Labs
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-11 00:00:00.000000000 Z
11
+ date: 2020-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,8 +108,50 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '4.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: morf
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: hcast
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: attr_validator
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
111
153
  description: Ruby Dependency Manager
112
- email:
154
+ email:
113
155
  executables:
114
156
  - rdm
115
157
  - rubocop
@@ -130,8 +172,6 @@ files:
130
172
  - docs/index.md
131
173
  - docs/interface_brainstorming.md
132
174
  - example/.rdm/helpers/render_helper.rb
133
- - example/.rdm/templates/configs/<%=config_path%>
134
- - example/.rdm/templates/configs/<%=role_config_path%>
135
175
  - example/.rdm/templates/package/.gitignore
136
176
  - example/.rdm/templates/package/.rspec
137
177
  - example/.rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>.rb
@@ -152,18 +192,14 @@ files:
152
192
  - example/application/web/package/web.rb
153
193
  - example/application/web/package/web/sample_controller.rb
154
194
  - example/bin/console
155
- - example/configs/app/default.yml
156
- - example/configs/app/production.yml
157
- - example/configs/database/default.yml
195
+ - example/config/app.yml
158
196
  - example/domain/core/Package.rb
159
197
  - example/domain/core/package/core.rb
160
198
  - example/domain/core/package/core/sample_service.rb
161
199
  - example/domain/core/spec/core/one_more_spec.rb
162
200
  - example/domain/core/spec/core/sample_service_spec.rb
163
- - example/env_files/development.env
164
- - example/env_files/production.env
165
- - example/env_files/test.env
166
201
  - example/infrastructure/repository/Package.rb
202
+ - example/infrastructure/repository/fixture.txt
167
203
  - example/infrastructure/repository/package/repository.rb
168
204
  - example/infrastructure/repository/package/repository/sample_repository.rb
169
205
  - example/infrastructure/repository/spec/example_spec.rb
@@ -179,19 +215,13 @@ files:
179
215
  - example/tests/run
180
216
  - lib/rdm.rb
181
217
  - lib/rdm/cli/compile_package.rb
182
- - lib/rdm/cli/config.rb
183
218
  - lib/rdm/cli/dependencies_controller.rb
184
219
  - lib/rdm/cli/diff_package.rb
185
220
  - lib/rdm/cli/diff_spec_runner.rb
186
221
  - lib/rdm/cli/gen_package.rb
187
222
  - lib/rdm/cli/init.rb
188
223
  - lib/rdm/cli/template_generator.rb
189
- - lib/rdm/config.rb
190
- - lib/rdm/config_locals.rb
191
- - lib/rdm/config_manager.rb
192
- - lib/rdm/config_scope.rb
193
224
  - lib/rdm/errors.rb
194
- - lib/rdm/gen/config.rb
195
225
  - lib/rdm/gen/init.rb
196
226
  - lib/rdm/gen/package.rb
197
227
  - lib/rdm/git/diff_command.rb
@@ -218,16 +248,11 @@ files:
218
248
  - lib/rdm/spec_runner/runner.rb
219
249
  - lib/rdm/spec_runner/spec_filename_matcher.rb
220
250
  - lib/rdm/spec_runner/view.rb
221
- - lib/rdm/templates/configs/<%=config_path%>
222
- - lib/rdm/templates/configs/<%=role_config_path%>
223
251
  - lib/rdm/templates/init/.rdm/helpers/render_helper.rb
224
252
  - lib/rdm/templates/init/Gemfile
225
253
  - lib/rdm/templates/init/Rdm.packages
226
254
  - lib/rdm/templates/init/Readme.md
227
255
  - lib/rdm/templates/init/bin/console
228
- - lib/rdm/templates/init/env_files/development.env
229
- - lib/rdm/templates/init/env_files/production.env
230
- - lib/rdm/templates/init/env_files/test.env
231
256
  - lib/rdm/templates/init/tests/.runignore
232
257
  - lib/rdm/templates/init/tests/diff_run
233
258
  - lib/rdm/templates/init/tests/run
@@ -241,12 +266,19 @@ files:
241
266
  - lib/rdm/templates/template_detector.rb
242
267
  - lib/rdm/templates/template_renderer.rb
243
268
  - lib/rdm/utils/file_utils.rb
269
+ - lib/rdm/utils/ostruct_utils.rb
244
270
  - lib/rdm/utils/render_util.rb
245
271
  - lib/rdm/utils/string_utils.rb
246
272
  - lib/rdm/version.rb
273
+ - lib/rdm/yml_config/config_caster.rb
274
+ - lib/rdm/yml_config/config_manager.rb
275
+ - lib/rdm/yml_config/config_validator.rb
276
+ - lib/rdm/yml_config/env_config.rb
277
+ - lib/rdm/yml_config/env_config_dsl.rb
278
+ - lib/rdm/yml_config/validate_config.rb
247
279
  - rdm.gemspec
248
280
  - spec/fixtures/SampleSource.rb
249
- - spec/fixtures/config.yml
281
+ - spec/fixtures/app.yml
250
282
  - spec/fixtures/sample_prj/Rdm.packages
251
283
  - spec/fixtures/sample_prj/infrastructure/web/Package.rb
252
284
  - spec/helpers/example_project_helper.rb
@@ -256,8 +288,6 @@ files:
256
288
  - spec/rdm/cli/diff_spec_runner_spec.rb
257
289
  - spec/rdm/cli/gen_package_spec.rb
258
290
  - spec/rdm/cli/init_spec.rb
259
- - spec/rdm/config_manager_spec.rb
260
- - spec/rdm/gen/config_spec.rb
261
291
  - spec/rdm/gen/init_spec.rb
262
292
  - spec/rdm/gen/package_spec.rb
263
293
  - spec/rdm/git/diff_manager_spec.rb
@@ -279,11 +309,15 @@ files:
279
309
  - spec/rdm/spec_runner_spec.rb
280
310
  - spec/rdm/templates/template_detector_spec.rb
281
311
  - spec/rdm/templates/template_renderer_spec.rb
312
+ - spec/rdm/yml_config/config_caster_spec.rb
313
+ - spec/rdm/yml_config/config_manager_spec.rb
314
+ - spec/rdm/yml_config/config_validator_spec.rb
315
+ - spec/rdm/yml_config/env_config_dsl_spec.rb
282
316
  - spec/spec_helper.rb
283
- homepage:
317
+ homepage:
284
318
  licenses: []
285
319
  metadata: {}
286
- post_install_message:
320
+ post_install_message:
287
321
  rdoc_options: []
288
322
  require_paths:
289
323
  - lib
@@ -298,14 +332,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
298
332
  - !ruby/object:Gem::Version
299
333
  version: '0'
300
334
  requirements: []
301
- rubyforge_project:
302
- rubygems_version: 2.5.2.3
303
- signing_key:
335
+ rubygems_version: 3.0.8
336
+ signing_key:
304
337
  specification_version: 4
305
338
  summary: Ruby Dependency Manager
306
339
  test_files:
307
340
  - spec/fixtures/SampleSource.rb
308
- - spec/fixtures/config.yml
341
+ - spec/fixtures/app.yml
309
342
  - spec/fixtures/sample_prj/Rdm.packages
310
343
  - spec/fixtures/sample_prj/infrastructure/web/Package.rb
311
344
  - spec/helpers/example_project_helper.rb
@@ -315,8 +348,6 @@ test_files:
315
348
  - spec/rdm/cli/diff_spec_runner_spec.rb
316
349
  - spec/rdm/cli/gen_package_spec.rb
317
350
  - spec/rdm/cli/init_spec.rb
318
- - spec/rdm/config_manager_spec.rb
319
- - spec/rdm/gen/config_spec.rb
320
351
  - spec/rdm/gen/init_spec.rb
321
352
  - spec/rdm/gen/package_spec.rb
322
353
  - spec/rdm/git/diff_manager_spec.rb
@@ -338,4 +369,8 @@ test_files:
338
369
  - spec/rdm/spec_runner_spec.rb
339
370
  - spec/rdm/templates/template_detector_spec.rb
340
371
  - spec/rdm/templates/template_renderer_spec.rb
372
+ - spec/rdm/yml_config/config_caster_spec.rb
373
+ - spec/rdm/yml_config/config_manager_spec.rb
374
+ - spec/rdm/yml_config/config_validator_spec.rb
375
+ - spec/rdm/yml_config/env_config_dsl_spec.rb
341
376
  - spec/spec_helper.rb
@@ -1,2 +0,0 @@
1
- <%=config_name%>:
2
- <%=config_locals%>
@@ -1,2 +0,0 @@
1
- <%=config_name%>:
2
- <%=config_locals%>
@@ -1,2 +0,0 @@
1
- app:
2
- name: "Sample app"
@@ -1,2 +0,0 @@
1
- app:
2
- name: "Sample app (Production)"
@@ -1,3 +0,0 @@
1
- database:
2
- username: "root"
3
- password: "root"
@@ -1,3 +0,0 @@
1
- RUBY_ENV=development
2
-
3
- APP_NAME=Application
@@ -1,5 +0,0 @@
1
- RUBY_ENV=production
2
-
3
- EXAMPLE_API_KEY=example_key_value
4
-
5
- APP_NAME=Application
@@ -1,3 +0,0 @@
1
- RUBY_ENV=test
2
-
3
- APP_NAME=Application
@@ -1,31 +0,0 @@
1
- class Rdm::CLI::Config
2
- def self.run(current_path:, config_name:, config_data: {}, stdout: $stdout)
3
- Rdm::CLI::Config.new(current_path, config_name, config_data, stdout).run
4
- end
5
-
6
- def initialize(current_path, config_name, config_data, stdout)
7
- @current_path = current_path
8
- @config_name = config_name
9
- @config_data = config_data
10
- @stdout = stdout
11
- end
12
-
13
- def run
14
- generated_files = Rdm::Gen::Config.generate(
15
- current_path: @current_path,
16
- config_name: @config_name,
17
- config_data: @config_data
18
- )
19
-
20
- puts "Following files were generated:"
21
- puts generated_files
22
- rescue Errno::ENOENT => e
23
- @stdout.puts "Error occurred. Possible reasons:\n #{Rdm::SOURCE_FILENAME} not found. Please run on directory containing #{Rdm::SOURCE_FILENAME} \n#{e.inspect}"
24
- rescue NoMethodError => e
25
- @stdout.puts e.message
26
- rescue Rdm::Errors::SourceFileDoesNotExist => e
27
- @stdout.puts "Rdm.packages was not found. Run 'rdm init' to create it"
28
- rescue Rdm::Errors::ConfigExists => e
29
- @stdout.puts "Config :#{e.message} already exists! Use other name"
30
- end
31
- end
@@ -1,11 +0,0 @@
1
- class Rdm::Config
2
- attr_accessor :name, :default_path, :role_path
3
-
4
- def self.build(name:, default_path:, role_path:)
5
- new.tap do |i|
6
- i.name = name
7
- i.default_path = default_path
8
- i.role_path = role_path
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- class Rdm::ConfigLocals
2
- def initialize(locals = {})
3
- @locals = locals
4
- end
5
-
6
- def to_s
7
- @locals
8
- .map {|key, value| "#{key}: #{value}"}
9
- .join("\n")
10
- end
11
- end
@@ -1,68 +0,0 @@
1
- require 'yaml'
2
- require 'erb'
3
-
4
- class Rdm::ConfigManager
5
- # Update configuration based on given config file
6
- # @param config [Rdm::Config] Config entity
7
- # @return root scope [Rdm::ConfigScope] Updated root scope
8
- def load_config(config, source:)
9
- if config.default_path
10
- full_default_path = File.join(source.root_path, config.default_path)
11
- update_using_file(full_default_path, raise_if_missing: true)
12
- end
13
- if config.role_path
14
- full_role_path = File.join(source.root_path, config.role_path)
15
- update_using_file(full_role_path, raise_if_missing: false)
16
- end
17
- root_scope
18
- end
19
-
20
- # Update configuration using given path to config file
21
- # @param config [Hash<String: AnyValue>] Hash with configuration
22
- # @return root scope [Rdm::ConfigScope] Updated root scope
23
- def update_using_file(path, raise_if_missing: true)
24
- if File.exist?(path)
25
- compiled_file = ::ERB.new(File.read(path)).result
26
- hash = YAML.load(compiled_file)
27
- update_using_hash(hash)
28
- elsif raise_if_missing
29
- raise "Config file is not found at path #{path}"
30
- end
31
- root_scope
32
- end
33
-
34
- # Update configuration based on given hash
35
- # @param config [Hash<String: AnyValue>] Hash with configuration
36
- # @return root scope [Rdm::ConfigScope] Updated root scope
37
- def update_using_hash(hash, scope: nil)
38
- scope ||= root_scope
39
-
40
- hash.each do |key, value|
41
- if value.is_a?(Hash)
42
- # Try using existing scope
43
- child_scope = scope.read_attribute(key)
44
- if !child_scope || !child_scope.is_a?(Rdm::ConfigScope)
45
- child_scope = Rdm::ConfigScope.new
46
- end
47
- update_using_hash(value, scope: child_scope)
48
- scope.write_attribute(key, child_scope)
49
- else
50
- scope.write_attribute(key, value)
51
- end
52
- end
53
- end
54
-
55
- def method_missing(method_name, *args)
56
- root_scope.send(method_name, *args)
57
- end
58
-
59
- def to_h
60
- root_scope.to_h
61
- end
62
-
63
- private
64
-
65
- def root_scope
66
- @root_scope ||= Rdm::ConfigScope.new
67
- end
68
- end