rdm 0.4.17 → 0.4.18

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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -8
  3. data/bin/rdm +10 -10
  4. data/example/.rdm/templates/configs/<%=config_path%> +2 -0
  5. data/example/.rdm/templates/configs/<%=role_config_path%> +2 -0
  6. data/example/Rdm.packages +17 -1
  7. data/example/configs/app/default.yml +2 -0
  8. data/example/configs/app/production.yml +2 -0
  9. data/example/configs/database/default.yml +3 -0
  10. data/example/env_files/development.env +3 -0
  11. data/example/env_files/production.env +5 -0
  12. data/example/env_files/test.env +3 -0
  13. data/example/infrastructure/repository/Package.rb +1 -0
  14. data/lib/rdm.rb +7 -14
  15. data/lib/rdm/cli/config.rb +31 -0
  16. data/lib/rdm/config.rb +11 -0
  17. data/lib/rdm/config_locals.rb +11 -0
  18. data/lib/rdm/config_manager.rb +68 -0
  19. data/lib/rdm/config_scope.rb +23 -0
  20. data/lib/rdm/errors.rb +0 -3
  21. data/lib/rdm/gen/config.rb +59 -0
  22. data/lib/rdm/gen/init.rb +4 -0
  23. data/lib/rdm/package.rb +9 -18
  24. data/lib/rdm/package_importer.rb +17 -3
  25. data/lib/rdm/package_parser.rb +0 -1
  26. data/lib/rdm/packages/compiler_service.rb +7 -1
  27. data/lib/rdm/settings.rb +21 -10
  28. data/lib/rdm/source.rb +18 -1
  29. data/lib/rdm/source_parser.rb +45 -2
  30. data/lib/rdm/spec_runner/runner.rb +2 -2
  31. data/lib/rdm/templates/configs/<%=config_path%> +2 -0
  32. data/lib/rdm/templates/configs/<%=role_config_path%> +2 -0
  33. data/lib/rdm/templates/init/Rdm.packages +12 -0
  34. data/lib/rdm/templates/init/env_files/development.env +3 -0
  35. data/lib/rdm/templates/init/env_files/production.env +3 -0
  36. data/lib/rdm/templates/init/env_files/test.env +3 -0
  37. data/lib/rdm/version.rb +1 -1
  38. data/rdm.gemspec +0 -3
  39. data/spec/fixtures/SampleSource.rb +4 -2
  40. data/spec/fixtures/config.yml +2 -0
  41. data/spec/rdm/cli/gen_package_spec.rb +2 -0
  42. data/spec/rdm/config_manager_spec.rb +136 -0
  43. data/spec/rdm/gen/config_spec.rb +31 -0
  44. data/spec/rdm/gen/init_spec.rb +12 -0
  45. data/spec/rdm/gen/package_spec.rb +0 -1
  46. data/spec/rdm/package_importer_spec.rb +2 -34
  47. data/spec/rdm/rdm_spec.rb +1 -1
  48. data/spec/rdm/source_parser_spec.rb +59 -0
  49. data/spec/spec_helper.rb +0 -1
  50. metadata +27 -63
  51. data/example/config/app.yml +0 -6
  52. data/example/infrastructure/repository/fixture.txt +0 -1
  53. data/lib/rdm/utils/ostruct_utils.rb +0 -12
  54. data/lib/rdm/yml_config/config_caster.rb +0 -32
  55. data/lib/rdm/yml_config/config_manager.rb +0 -39
  56. data/lib/rdm/yml_config/config_validator.rb +0 -51
  57. data/lib/rdm/yml_config/env_config.rb +0 -46
  58. data/lib/rdm/yml_config/env_config_dsl.rb +0 -92
  59. data/lib/rdm/yml_config/validate_config.rb +0 -13
  60. data/spec/fixtures/app.yml +0 -17
  61. data/spec/rdm/yml_config/config_caster_spec.rb +0 -64
  62. data/spec/rdm/yml_config/config_manager_spec.rb +0 -7
  63. data/spec/rdm/yml_config/config_validator_spec.rb +0 -190
  64. data/spec/rdm/yml_config/env_config_dsl_spec.rb +0 -123
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rdm::Gen::Config do
4
+ include ExampleProjectHelper
5
+
6
+ subject { described_class }
7
+
8
+ describe "::generate" do
9
+ before { initialize_example_project }
10
+ after { reset_example_project }
11
+
12
+ context "sample config" do
13
+ before do
14
+ subject.generate(
15
+ config_name: 'mailing_system',
16
+ current_path: example_project_path
17
+ )
18
+ end
19
+
20
+ it "generates sample config" do
21
+ FileUtils.cd(example_project_path) do
22
+ ensure_exists("configs/mailing_system/default.yml")
23
+ end
24
+ end
25
+
26
+ it "add config line to Rdm.packages" do
27
+ ensure_content(rdm_source_file, 'config :mailing_system')
28
+ end
29
+ end
30
+ end
31
+ end
@@ -18,6 +18,9 @@ describe Rdm::Gen::Init do
18
18
  ensure_exists("Gemfile")
19
19
  ensure_exists("Readme.md")
20
20
  ensure_exists("bin/console")
21
+ ensure_exists("env_files/test.env")
22
+ ensure_exists("env_files/development.env")
23
+ ensure_exists("env_files/production.env")
21
24
  end
22
25
  end
23
26
 
@@ -33,6 +36,15 @@ describe Rdm::Gen::Init do
33
36
  ensure_exists(".rdm/templates/package/bin/console")
34
37
  end
35
38
  end
39
+
40
+ it "has generated config templates" do
41
+ subject.generate(current_path: example_project_path, stdout: stdout)
42
+
43
+ FileUtils.cd(example_project_path) do
44
+ ensure_exists(".rdm/templates/configs/<%=config_path%>")
45
+ ensure_exists(".rdm/templates/configs/<%=role_config_path%>")
46
+ end
47
+ end
36
48
  end
37
49
 
38
50
  context "prevents double execution" do
@@ -82,7 +82,6 @@ describe Rdm::Gen::Package do
82
82
  package_name: "some",
83
83
  local_path: "domain/some",
84
84
  )
85
-
86
85
  expect {
87
86
  subject.generate(
88
87
  current_path: example_project_path,
@@ -8,28 +8,17 @@ describe Rdm::PackageImporter do
8
8
  dependencies.each do |dependency|
9
9
  package.import(dependency)
10
10
  end
11
- package.set_environments do
12
- array 'some_key', each: :string do
13
- length({ min: 3 })
14
- end
15
- end
16
-
17
11
  package
18
12
  end
19
13
 
20
14
  def build_source(packages:)
21
15
  source = Rdm::Source.new(root_path: nil)
22
- source.init_with(packages: packages)
16
+ source.init_with(packages: packages, configs: {})
23
17
  source
24
18
  end
25
19
 
26
- before(:each) do
20
+ before do
27
21
  Rdm::PackageImporter.reset!
28
- Rdm::ConfigManager.reset!
29
-
30
- Rdm.setup do
31
- config_path File.expand_path(File.join(__dir__, '../fixtures/app.yml'))
32
- end
33
22
  end
34
23
 
35
24
  describe "#import_package" do
@@ -75,26 +64,5 @@ describe Rdm::PackageImporter do
75
64
  expect(imported).to_not include("factory")
76
65
  end
77
66
  end
78
-
79
- context 'sets config variables' do
80
- it 'only for imported packages' do
81
- web_pack = build_package("web", dependencies: ["core"])
82
- core_pack = build_package("core")
83
- factory_pack = build_package("factory")
84
-
85
- source = build_source(packages: {"web" => web_pack, "core" => core_pack, "factory" => factory_pack})
86
-
87
- imported = subject.import_package("web", source: source)
88
-
89
- expect(Rdm::ConfigManager.web.some_key).to match(["value1", "value2", "value3"])
90
- expect(Rdm::ConfigManager.core.some_key).to match(["value1", "value2", "value3"])
91
-
92
- expect{
93
- Rdm::ConfigManager.factory
94
- }.to raise_error(
95
- ArgumentError, ":factory configuration was not defined for current package. Add `import 'factory'` to your Package.rb file"
96
- )
97
- end
98
- end
99
67
  end
100
68
  end
@@ -29,7 +29,7 @@ describe Rdm do
29
29
 
30
30
  context "config" do
31
31
  it "returns config" do
32
- expect(Rdm.config).to eq(Rdm::ConfigManager)
32
+ expect(Rdm.config).to be_a(Rdm::ConfigManager)
33
33
  end
34
34
  end
35
35
 
@@ -32,6 +32,12 @@ describe Rdm::SourceParser do
32
32
  expect(paths).to include("application/web")
33
33
  expect(paths).to include("domain/core")
34
34
  end
35
+
36
+ it "parses all config names" do
37
+ names = @source.config_names
38
+ expect(names.count).to be(1)
39
+ expect(names).to include("database")
40
+ end
35
41
  end
36
42
 
37
43
 
@@ -64,5 +70,58 @@ describe Rdm::SourceParser do
64
70
  expect(paths).to include("application/web")
65
71
  expect(paths).to include("domain/core")
66
72
  end
73
+
74
+ it "parses all config names" do
75
+ names = @source.config_names
76
+ expect(names.count).to be(2)
77
+ expect(names).to include("database")
78
+ end
79
+ end
80
+
81
+ describe "::read_and_init_source" do
82
+ before { initialize_example_project }
83
+ after { reset_example_project }
84
+
85
+ subject { described_class }
86
+ let(:stdout) { SpecLogger.new }
87
+
88
+ describe "#init_and_set_env_variables" do
89
+ context "with defined role" do
90
+ it "load env_file variables into ENV hash" do
91
+ subject.read_and_init_source(@rdm_source_file)
92
+
93
+ expect(ENV['EXAMPLE_API_KEY']).to eq('example_key_value')
94
+ expect(ENV['APP_NAME']).to eq('Application')
95
+ end
96
+ end
97
+
98
+ context "with undefined role" do
99
+ it "puts warning message" do
100
+ Rdm::Utils::FileUtils.change_file @rdm_source_file do |line|
101
+ line.include?("ENV['ENV_FILE'] || \"production\"") ? 'env_file_name "stading"' : line
102
+ end
103
+ subject.read_and_init_source(@rdm_source_file, stdout: stdout)
104
+
105
+ expect(stdout.output).to include("WARNING! Environment file 'stading' was not found. Please, add /tmp/example/env_files/stading.env file...")
106
+ end
107
+ end
108
+
109
+ context "when try to overwrite ENV variable" do
110
+ before do
111
+ ENV['RUBY_ENV'] = 'test'
112
+
113
+ subject.read_and_init_source(@rdm_source_file, stdout: stdout)
114
+ end
115
+
116
+ it 'puts warning message' do
117
+ expect(stdout.output).to include("WARNING! Environment file 'production' overwrites ENV['RUBY_ENV'] variable from 'test' to 'production' ...")
118
+ end
119
+
120
+ it 'overwrites ENV variable' do
121
+ expect(ENV['RUBY_ENV']).to eq('production')
122
+ expect(ENV['APP_NAME']).to eq('Application')
123
+ end
124
+ end
125
+ end
67
126
  end
68
127
  end
@@ -26,7 +26,6 @@ end
26
26
 
27
27
  Rdm.setup do
28
28
  silence_missing_package_file true
29
- config_path File.join(__dir__, 'fixtures', 'app.yml')
30
29
  end
31
30
 
32
31
  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.17
4
+ version: 0.4.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Droid Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-25 00:00:00.000000000 Z
11
+ date: 2020-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,48 +108,6 @@ 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'
153
111
  description: Ruby Dependency Manager
154
112
  email:
155
113
  executables:
@@ -172,6 +130,8 @@ files:
172
130
  - docs/index.md
173
131
  - docs/interface_brainstorming.md
174
132
  - example/.rdm/helpers/render_helper.rb
133
+ - example/.rdm/templates/configs/<%=config_path%>
134
+ - example/.rdm/templates/configs/<%=role_config_path%>
175
135
  - example/.rdm/templates/package/.gitignore
176
136
  - example/.rdm/templates/package/.rspec
177
137
  - example/.rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>.rb
@@ -192,14 +152,18 @@ files:
192
152
  - example/application/web/package/web.rb
193
153
  - example/application/web/package/web/sample_controller.rb
194
154
  - example/bin/console
195
- - example/config/app.yml
155
+ - example/configs/app/default.yml
156
+ - example/configs/app/production.yml
157
+ - example/configs/database/default.yml
196
158
  - example/domain/core/Package.rb
197
159
  - example/domain/core/package/core.rb
198
160
  - example/domain/core/package/core/sample_service.rb
199
161
  - example/domain/core/spec/core/one_more_spec.rb
200
162
  - 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
201
166
  - example/infrastructure/repository/Package.rb
202
- - example/infrastructure/repository/fixture.txt
203
167
  - example/infrastructure/repository/package/repository.rb
204
168
  - example/infrastructure/repository/package/repository/sample_repository.rb
205
169
  - example/infrastructure/repository/spec/example_spec.rb
@@ -215,13 +179,19 @@ files:
215
179
  - example/tests/run
216
180
  - lib/rdm.rb
217
181
  - lib/rdm/cli/compile_package.rb
182
+ - lib/rdm/cli/config.rb
218
183
  - lib/rdm/cli/dependencies_controller.rb
219
184
  - lib/rdm/cli/diff_package.rb
220
185
  - lib/rdm/cli/diff_spec_runner.rb
221
186
  - lib/rdm/cli/gen_package.rb
222
187
  - lib/rdm/cli/init.rb
223
188
  - 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
224
193
  - lib/rdm/errors.rb
194
+ - lib/rdm/gen/config.rb
225
195
  - lib/rdm/gen/init.rb
226
196
  - lib/rdm/gen/package.rb
227
197
  - lib/rdm/git/diff_command.rb
@@ -248,11 +218,16 @@ files:
248
218
  - lib/rdm/spec_runner/runner.rb
249
219
  - lib/rdm/spec_runner/spec_filename_matcher.rb
250
220
  - lib/rdm/spec_runner/view.rb
221
+ - lib/rdm/templates/configs/<%=config_path%>
222
+ - lib/rdm/templates/configs/<%=role_config_path%>
251
223
  - lib/rdm/templates/init/.rdm/helpers/render_helper.rb
252
224
  - lib/rdm/templates/init/Gemfile
253
225
  - lib/rdm/templates/init/Rdm.packages
254
226
  - lib/rdm/templates/init/Readme.md
255
227
  - 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
256
231
  - lib/rdm/templates/init/tests/.runignore
257
232
  - lib/rdm/templates/init/tests/diff_run
258
233
  - lib/rdm/templates/init/tests/run
@@ -266,19 +241,12 @@ files:
266
241
  - lib/rdm/templates/template_detector.rb
267
242
  - lib/rdm/templates/template_renderer.rb
268
243
  - lib/rdm/utils/file_utils.rb
269
- - lib/rdm/utils/ostruct_utils.rb
270
244
  - lib/rdm/utils/render_util.rb
271
245
  - lib/rdm/utils/string_utils.rb
272
246
  - 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
279
247
  - rdm.gemspec
280
248
  - spec/fixtures/SampleSource.rb
281
- - spec/fixtures/app.yml
249
+ - spec/fixtures/config.yml
282
250
  - spec/fixtures/sample_prj/Rdm.packages
283
251
  - spec/fixtures/sample_prj/infrastructure/web/Package.rb
284
252
  - spec/helpers/example_project_helper.rb
@@ -288,6 +256,8 @@ files:
288
256
  - spec/rdm/cli/diff_spec_runner_spec.rb
289
257
  - spec/rdm/cli/gen_package_spec.rb
290
258
  - spec/rdm/cli/init_spec.rb
259
+ - spec/rdm/config_manager_spec.rb
260
+ - spec/rdm/gen/config_spec.rb
291
261
  - spec/rdm/gen/init_spec.rb
292
262
  - spec/rdm/gen/package_spec.rb
293
263
  - spec/rdm/git/diff_manager_spec.rb
@@ -309,10 +279,6 @@ files:
309
279
  - spec/rdm/spec_runner_spec.rb
310
280
  - spec/rdm/templates/template_detector_spec.rb
311
281
  - 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
316
282
  - spec/spec_helper.rb
317
283
  homepage:
318
284
  licenses: []
@@ -338,7 +304,7 @@ specification_version: 4
338
304
  summary: Ruby Dependency Manager
339
305
  test_files:
340
306
  - spec/fixtures/SampleSource.rb
341
- - spec/fixtures/app.yml
307
+ - spec/fixtures/config.yml
342
308
  - spec/fixtures/sample_prj/Rdm.packages
343
309
  - spec/fixtures/sample_prj/infrastructure/web/Package.rb
344
310
  - spec/helpers/example_project_helper.rb
@@ -348,6 +314,8 @@ test_files:
348
314
  - spec/rdm/cli/diff_spec_runner_spec.rb
349
315
  - spec/rdm/cli/gen_package_spec.rb
350
316
  - spec/rdm/cli/init_spec.rb
317
+ - spec/rdm/config_manager_spec.rb
318
+ - spec/rdm/gen/config_spec.rb
351
319
  - spec/rdm/gen/init_spec.rb
352
320
  - spec/rdm/gen/package_spec.rb
353
321
  - spec/rdm/git/diff_manager_spec.rb
@@ -369,8 +337,4 @@ test_files:
369
337
  - spec/rdm/spec_runner_spec.rb
370
338
  - spec/rdm/templates/template_detector_spec.rb
371
339
  - 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
376
340
  - spec/spec_helper.rb
@@ -1,6 +0,0 @@
1
- database:
2
- username: "root"
3
- password: "root"
4
- core:
5
- app_name: "RdmExampleProject"
6
-
@@ -1 +0,0 @@
1
- Repository spec working here!
@@ -1,12 +0,0 @@
1
- require 'ostruct'
2
-
3
- class Rdm::Utils::Ostruct
4
- class << self
5
- def to_recursive_ostruct(hash)
6
- OpenStruct.new(hash.each_with_object({}) do |(key, val), memo|
7
- memo[key] = val.is_a?(Hash) ? to_recursive_ostruct(val) : val
8
- end)
9
- end
10
- end
11
- end
12
-
@@ -1,32 +0,0 @@
1
- require 'morf'
2
-
3
- class Rdm::ConfigCaster
4
- def initialize(envs)
5
- @envs = envs
6
- end
7
-
8
- def cast(hash)
9
- hash[@envs.name] ||= {}
10
- caster.cast(hash, input_keys: :string, skip_unexpected_attributes: true)
11
- end
12
-
13
-
14
- def to_hcast_string(env)
15
- eval_string = "#{env.type} :#{env.name}, optional: #{env.optional}"
16
- eval_string += env.is_array? ? ", each: :#{env.children.first.type}" : ""
17
- eval_string += env.is_hash? ? %Q( do \n #{env.children.map { |e| to_hcast_string(e) }.join("\n")} \nend) : ""
18
-
19
- eval_string
20
- end
21
-
22
- private
23
-
24
- def caster
25
- @caster ||= Class.new
26
- @caster.include(Morf::Caster)
27
-
28
- @caster.class_eval "attributes do\n #{to_hcast_string(@envs)}\n end"
29
-
30
- @caster
31
- end
32
- end