rdm 0.4.14.2 → 0.4.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +26 -19
- data/bin/rdm +10 -10
- data/example/Rdm.packages +1 -17
- data/example/config/app.yml +6 -0
- data/example/infrastructure/repository/Package.rb +0 -1
- data/example/infrastructure/repository/fixture.txt +1 -0
- data/lib/rdm.rb +14 -7
- data/lib/rdm/errors.rb +3 -0
- data/lib/rdm/gen/init.rb +0 -4
- data/lib/rdm/package.rb +18 -9
- data/lib/rdm/package_importer.rb +4 -18
- data/lib/rdm/package_parser.rb +1 -0
- data/lib/rdm/packages/compiler_service.rb +1 -7
- data/lib/rdm/settings.rb +10 -21
- data/lib/rdm/source.rb +1 -18
- data/lib/rdm/source_parser.rb +2 -45
- data/lib/rdm/templates/init/Rdm.packages +0 -12
- data/lib/rdm/utils/ostruct_utils.rb +12 -0
- data/lib/rdm/version.rb +1 -1
- data/lib/rdm/yml_config/config_caster.rb +32 -0
- data/lib/rdm/yml_config/config_manager.rb +39 -0
- data/lib/rdm/yml_config/config_validator.rb +51 -0
- data/lib/rdm/yml_config/env_config.rb +46 -0
- data/lib/rdm/yml_config/env_config_dsl.rb +92 -0
- data/lib/rdm/yml_config/validate_config.rb +13 -0
- data/rdm.gemspec +3 -0
- data/spec/fixtures/SampleSource.rb +2 -4
- data/spec/fixtures/app.yml +17 -0
- data/spec/rdm/cli/gen_package_spec.rb +0 -2
- data/spec/rdm/gen/init_spec.rb +0 -12
- data/spec/rdm/gen/package_spec.rb +1 -0
- data/spec/rdm/package_importer_spec.rb +34 -2
- data/spec/rdm/rdm_spec.rb +1 -1
- data/spec/rdm/source_parser_spec.rb +0 -59
- data/spec/rdm/yml_config/config_caster_spec.rb +64 -0
- data/spec/rdm/yml_config/config_manager_spec.rb +7 -0
- data/spec/rdm/yml_config/config_validator_spec.rb +190 -0
- data/spec/rdm/yml_config/env_config_dsl_spec.rb +123 -0
- data/spec/spec_helper.rb +1 -0
- metadata +69 -34
- data/example/.rdm/templates/configs/<%=config_path%> +0 -2
- data/example/.rdm/templates/configs/<%=role_config_path%> +0 -2
- data/example/configs/app/default.yml +0 -2
- data/example/configs/app/production.yml +0 -2
- data/example/configs/database/default.yml +0 -3
- data/example/env_files/development.env +0 -3
- data/example/env_files/production.env +0 -5
- data/example/env_files/test.env +0 -3
- data/lib/rdm/cli/config.rb +0 -31
- data/lib/rdm/config.rb +0 -11
- data/lib/rdm/config_locals.rb +0 -11
- data/lib/rdm/config_manager.rb +0 -68
- data/lib/rdm/config_scope.rb +0 -23
- data/lib/rdm/gen/config.rb +0 -59
- data/lib/rdm/templates/configs/<%=config_path%> +0 -2
- data/lib/rdm/templates/configs/<%=role_config_path%> +0 -2
- data/lib/rdm/templates/init/env_files/development.env +0 -3
- data/lib/rdm/templates/init/env_files/production.env +0 -3
- data/lib/rdm/templates/init/env_files/test.env +0 -3
- data/spec/fixtures/config.yml +0 -2
- data/spec/rdm/config_manager_spec.rb +0 -136
- data/spec/rdm/gen/config_spec.rb +0 -31
data/rdm.gemspec
CHANGED
@@ -23,4 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "codecov"
|
24
24
|
spec.add_dependency "activesupport"
|
25
25
|
spec.add_dependency "commander", "~> 4.4"
|
26
|
+
spec.add_dependency "morf"
|
27
|
+
spec.add_dependency "hcast"
|
28
|
+
spec.add_dependency "attr_validator"
|
26
29
|
end
|
data/spec/rdm/gen/init_spec.rb
CHANGED
@@ -18,9 +18,6 @@ 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")
|
24
21
|
end
|
25
22
|
end
|
26
23
|
|
@@ -36,15 +33,6 @@ describe Rdm::Gen::Init do
|
|
36
33
|
ensure_exists(".rdm/templates/package/bin/console")
|
37
34
|
end
|
38
35
|
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
|
48
36
|
end
|
49
37
|
|
50
38
|
context "prevents double execution" do
|
@@ -8,17 +8,28 @@ 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
|
+
|
11
17
|
package
|
12
18
|
end
|
13
19
|
|
14
20
|
def build_source(packages:)
|
15
21
|
source = Rdm::Source.new(root_path: nil)
|
16
|
-
source.init_with(packages: packages
|
22
|
+
source.init_with(packages: packages)
|
17
23
|
source
|
18
24
|
end
|
19
25
|
|
20
|
-
before do
|
26
|
+
before(:each) do
|
21
27
|
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
|
22
33
|
end
|
23
34
|
|
24
35
|
describe "#import_package" do
|
@@ -64,5 +75,26 @@ describe Rdm::PackageImporter do
|
|
64
75
|
expect(imported).to_not include("factory")
|
65
76
|
end
|
66
77
|
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
|
67
99
|
end
|
68
100
|
end
|
data/spec/rdm/rdm_spec.rb
CHANGED
@@ -32,12 +32,6 @@ 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
|
41
35
|
end
|
42
36
|
|
43
37
|
|
@@ -70,58 +64,5 @@ describe Rdm::SourceParser do
|
|
70
64
|
expect(paths).to include("application/web")
|
71
65
|
expect(paths).to include("domain/core")
|
72
66
|
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
|
126
67
|
end
|
127
68
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rdm::ConfigCaster do
|
4
|
+
subject { described_class.new(env) }
|
5
|
+
|
6
|
+
describe "#to_hcast_string" do
|
7
|
+
context 'for string env' do
|
8
|
+
let(:env) {
|
9
|
+
Rdm::EnvConfig.new(
|
10
|
+
name: :string_env,
|
11
|
+
type: :string
|
12
|
+
)
|
13
|
+
}
|
14
|
+
|
15
|
+
it 'generates proper string' do
|
16
|
+
expect(
|
17
|
+
subject.to_hcast_string(env)
|
18
|
+
).to eq("string :string_env, optional: false")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'for array env' do
|
23
|
+
let(:env) {
|
24
|
+
Rdm::EnvConfig.new(
|
25
|
+
name: :array_env,
|
26
|
+
type: :array,
|
27
|
+
children: [
|
28
|
+
Rdm::EnvConfig.new(
|
29
|
+
name: :string_env,
|
30
|
+
type: :string
|
31
|
+
)
|
32
|
+
]
|
33
|
+
)
|
34
|
+
}
|
35
|
+
|
36
|
+
it 'generates proper string' do
|
37
|
+
expect(
|
38
|
+
subject.to_hcast_string(env)
|
39
|
+
).to eq("array :array_env, optional: false, each: :string")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'for hash env' do
|
44
|
+
let(:env) {
|
45
|
+
Rdm::EnvConfig.new(
|
46
|
+
name: :hash_env,
|
47
|
+
type: :hash,
|
48
|
+
children: [
|
49
|
+
Rdm::EnvConfig.new(
|
50
|
+
name: :string_env,
|
51
|
+
type: :string
|
52
|
+
)
|
53
|
+
]
|
54
|
+
)
|
55
|
+
}
|
56
|
+
|
57
|
+
it 'generates proper string' do
|
58
|
+
expect(
|
59
|
+
subject.to_hcast_string(env)
|
60
|
+
).to eq("hash :hash_env, optional: false do \n string :string_env, optional: false \nend")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rdm::ConfigValidator do
|
4
|
+
|
5
|
+
let(:hash_config) {
|
6
|
+
{
|
7
|
+
example_config: {
|
8
|
+
example_array_config: ['hello', 'world'],
|
9
|
+
example_symbol_config: :values,
|
10
|
+
example_integer_config: 25,
|
11
|
+
example_email_config: 'info@rdm.com'
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
let(:array_config) {
|
17
|
+
Rdm::EnvConfig.new(
|
18
|
+
name: 'example_array_config',
|
19
|
+
type: :array,
|
20
|
+
validates: nil,
|
21
|
+
children: [
|
22
|
+
Rdm::EnvConfig.new(
|
23
|
+
name: nil,
|
24
|
+
type: :string,
|
25
|
+
validates: {
|
26
|
+
length: {
|
27
|
+
equal_to: 5
|
28
|
+
}
|
29
|
+
}
|
30
|
+
)
|
31
|
+
]
|
32
|
+
)
|
33
|
+
}
|
34
|
+
let(:symbol_config) {
|
35
|
+
Rdm::EnvConfig.new(
|
36
|
+
name: 'example_symbol_config',
|
37
|
+
type: :symbol,
|
38
|
+
validates: {
|
39
|
+
inclusion: {
|
40
|
+
in: [:example, :symbol, :config, :values]
|
41
|
+
}
|
42
|
+
}
|
43
|
+
)
|
44
|
+
}
|
45
|
+
let(:integer_config) {
|
46
|
+
Rdm::EnvConfig.new(
|
47
|
+
name: 'example_integer_config',
|
48
|
+
type: :integer,
|
49
|
+
validates: {
|
50
|
+
numericality: {
|
51
|
+
greater_than_or_equal_to: 5,
|
52
|
+
less_than: 50
|
53
|
+
}
|
54
|
+
}
|
55
|
+
)
|
56
|
+
}
|
57
|
+
let(:email_config) {
|
58
|
+
Rdm::EnvConfig.new(
|
59
|
+
name: 'example_email_config',
|
60
|
+
type: :string,
|
61
|
+
optional: true,
|
62
|
+
validates: {
|
63
|
+
email: true,
|
64
|
+
presence: true
|
65
|
+
}
|
66
|
+
)
|
67
|
+
}
|
68
|
+
|
69
|
+
let(:env_config) {
|
70
|
+
Rdm::EnvConfig.new(
|
71
|
+
name: 'example_config',
|
72
|
+
type: :hash,
|
73
|
+
optional: true,
|
74
|
+
default: nil,
|
75
|
+
validates: nil,
|
76
|
+
children: [
|
77
|
+
array_config,
|
78
|
+
symbol_config,
|
79
|
+
integer_config,
|
80
|
+
email_config
|
81
|
+
]
|
82
|
+
)
|
83
|
+
}
|
84
|
+
|
85
|
+
describe '#validate' do
|
86
|
+
context 'for symbol config' do
|
87
|
+
it 'not raises error for valid params' do
|
88
|
+
expect {
|
89
|
+
described_class.new(symbol_config).validate!({example_symbol_config: :example})
|
90
|
+
}.not_to raise_error
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'raises ArgumentError if invalid params' do
|
94
|
+
expect {
|
95
|
+
described_class.new(symbol_config).validate!({example_symbol_config: :unpermitted_parameter})
|
96
|
+
}.to raise_error Rdm::Errors::InvalidConfig
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'returns OpenStruct' do
|
100
|
+
expect(
|
101
|
+
described_class.new(symbol_config).validate!({example_symbol_config: :example})
|
102
|
+
).to eq(OpenStruct.new({example_symbol_config: :example}))
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'for email config' do
|
107
|
+
it 'not raises error for valid params' do
|
108
|
+
expect {
|
109
|
+
described_class.new(email_config).validate!({example_email_config: 'hello@world.ru'})
|
110
|
+
}.not_to raise_error
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'raises ArgumentError if invalid params' do
|
114
|
+
expect {
|
115
|
+
described_class.new(email_config).validate!({example_email_config: 'helloworld'})
|
116
|
+
}.to raise_error Rdm::Errors::InvalidConfig
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'returns OpenStruct' do
|
120
|
+
expect(
|
121
|
+
described_class.new(email_config).validate!({example_email_config: 'hello@world.ru'})
|
122
|
+
).to eq(OpenStruct.new({example_email_config: 'hello@world.ru'}))
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'for integer config' do
|
127
|
+
it 'not raises error for valid params' do
|
128
|
+
expect {
|
129
|
+
described_class.new(integer_config).validate!({example_integer_config: 5})
|
130
|
+
}.not_to raise_error
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'not raises error for valid params' do
|
134
|
+
expect {
|
135
|
+
described_class.new(integer_config).validate!({example_integer_config: 4})
|
136
|
+
}.to raise_error Rdm::Errors::InvalidConfig
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'returns OpenStruct' do
|
140
|
+
expect(
|
141
|
+
described_class.new(integer_config).validate!({example_integer_config: 5})
|
142
|
+
).to eq(OpenStruct.new({example_integer_config: 5}))
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'for array config' do
|
147
|
+
it 'not raises error for valid params' do
|
148
|
+
expect {
|
149
|
+
described_class.new(symbol_config).validate!({example_array_config: ['hello', 'world']})
|
150
|
+
}.not_to raise_error
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'returns OpenStruct' do
|
154
|
+
expect(
|
155
|
+
described_class.new(integer_config).validate!({example_array_config: ['hello', 'world']})
|
156
|
+
).to eq(OpenStruct.new({example_array_config: ['hello', 'world']}))
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'for hash config' do
|
161
|
+
it 'not raises error for valid params' do
|
162
|
+
expect {
|
163
|
+
described_class.new(symbol_config).validate!({example_array_config: ['hello', 'world']})
|
164
|
+
}.not_to raise_error
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'returns OpenStruct' do
|
168
|
+
expect(
|
169
|
+
described_class.new(integer_config).validate!(
|
170
|
+
{
|
171
|
+
example_array_config: ['hello', 'world'],
|
172
|
+
example_integer_config: 5,
|
173
|
+
example_email_config: 'hello@world.pro',
|
174
|
+
example_symbol_config: :example
|
175
|
+
}
|
176
|
+
)
|
177
|
+
).to match(
|
178
|
+
OpenStruct.new(
|
179
|
+
{
|
180
|
+
example_array_config: ['hello', 'world'],
|
181
|
+
example_integer_config: 5,
|
182
|
+
example_email_config: 'hello@world.pro',
|
183
|
+
example_symbol_config: :example
|
184
|
+
}
|
185
|
+
)
|
186
|
+
)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|