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/lib/rdm/config_scope.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
class Rdm::ConfigScope
|
2
|
-
def initialize(attributes = {})
|
3
|
-
@attributes = attributes
|
4
|
-
end
|
5
|
-
|
6
|
-
def read_attribute(key)
|
7
|
-
@attributes[key.to_s]
|
8
|
-
end
|
9
|
-
|
10
|
-
def write_attribute(key, value)
|
11
|
-
@attributes[key.to_s] = value
|
12
|
-
end
|
13
|
-
|
14
|
-
def method_missing(method_name, *_args)
|
15
|
-
read_attribute(method_name)
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_h
|
19
|
-
@attributes.each_with_object({}) do |(k, v), h|
|
20
|
-
h[k] = Rdm::ConfigScope === v ? v.to_h : v
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/rdm/gen/config.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
class Rdm::Gen::Config
|
2
|
-
TEMPLATE_NAME = 'configs'
|
3
|
-
|
4
|
-
def self.generate(config_name:, current_path:, config_data: {})
|
5
|
-
Rdm::Gen::Config.new(config_name, current_path, config_data = {}).generate
|
6
|
-
end
|
7
|
-
|
8
|
-
def initialize(config_name, current_path, config_data)
|
9
|
-
@current_path = current_path
|
10
|
-
@config_name = config_name
|
11
|
-
@source = get_source
|
12
|
-
|
13
|
-
@config_locals = Rdm::ConfigLocals.new(config_data)
|
14
|
-
end
|
15
|
-
|
16
|
-
def generate
|
17
|
-
@locals = {
|
18
|
-
config_name: @config_name,
|
19
|
-
config_locals: @config_locals,
|
20
|
-
config_path: config_path(@config_name),
|
21
|
-
role_config_path: role_config_path(@config_name)
|
22
|
-
}
|
23
|
-
|
24
|
-
generated_files = Rdm::Handlers::TemplateHandler.generate(
|
25
|
-
current_path: @current_path,
|
26
|
-
locals: @locals,
|
27
|
-
template_name: TEMPLATE_NAME,
|
28
|
-
local_path: './'
|
29
|
-
)
|
30
|
-
|
31
|
-
Rdm::SourceModifier.add_config(@config_name, get_source.root_path)
|
32
|
-
|
33
|
-
generated_files
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def get_source
|
39
|
-
@source ||= Rdm::SourceParser.read_and_init_source(Rdm::SourceLocator.locate(@current_path))
|
40
|
-
end
|
41
|
-
|
42
|
-
def config_path(config_name)
|
43
|
-
Rdm.settings.read_setting(
|
44
|
-
:config_path,
|
45
|
-
vars: {
|
46
|
-
config_name: config_name
|
47
|
-
}
|
48
|
-
)
|
49
|
-
end
|
50
|
-
|
51
|
-
def role_config_path(config_name)
|
52
|
-
Rdm.settings.read_setting(
|
53
|
-
:role_config_path,
|
54
|
-
vars: {
|
55
|
-
config_name: config_name
|
56
|
-
}
|
57
|
-
)
|
58
|
-
end
|
59
|
-
end
|
data/spec/fixtures/config.yml
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Rdm::ConfigManager do
|
4
|
-
subject { Rdm::ConfigManager.new }
|
5
|
-
|
6
|
-
let(:example_path) {
|
7
|
-
Pathname.new(
|
8
|
-
File.join(File.expand_path('../../../', __FILE__), 'example')
|
9
|
-
)
|
10
|
-
}
|
11
|
-
let(:config_manager) { Rdm::ConfigManager.new }
|
12
|
-
let(:source_file) { example_path.join('Rdm.packages').to_s }
|
13
|
-
let(:source) { Rdm::SourceParser.read_and_init_source(source_file)}
|
14
|
-
|
15
|
-
describe "#load_config" do
|
16
|
-
context "config.default_path" do
|
17
|
-
let(:config){ Rdm::Config.build(name: "name", default_path: "configs/app/default.yml", role_path: nil) }
|
18
|
-
it "works" do
|
19
|
-
config_manager.load_config(config, source: source)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "config.role_path" do
|
24
|
-
let(:config){ Rdm::Config.build(name: "name", default_path: nil, role_path: "configs/app/production.yml") }
|
25
|
-
it "works" do
|
26
|
-
config_manager.load_config(config, source: source)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#update_using_file" do
|
32
|
-
context "file missing and raise_if_missing=true" do
|
33
|
-
let(:config){ Rdm::Config.build(name: "name", default_path: "configs/app/not-there.yml", role_path: nil) }
|
34
|
-
it "raises" do
|
35
|
-
expect{
|
36
|
-
config_manager.load_config(config, source: source)
|
37
|
-
}.to raise_error(RuntimeError, Regexp.new("Config file is not found at path"))
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "#update_using_file" do
|
43
|
-
let(:fixtures_path) {
|
44
|
-
File.join(File.expand_path("../../", __FILE__), 'fixtures')
|
45
|
-
}
|
46
|
-
|
47
|
-
before :each do
|
48
|
-
subject.update_using_file(File.join(fixtures_path, "config.yml"))
|
49
|
-
end
|
50
|
-
|
51
|
-
it "parses yml with erb correctly" do
|
52
|
-
expect(subject.development.foo).to eq("bar")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "#update_using_hash" do
|
57
|
-
before :each do
|
58
|
-
subject.update_using_hash(
|
59
|
-
database: {
|
60
|
-
username: "foo",
|
61
|
-
password: "bar"
|
62
|
-
},
|
63
|
-
lib_name: "rdm",
|
64
|
-
version: 1,
|
65
|
-
published: true,
|
66
|
-
draft: false,
|
67
|
-
features: ["dependency_manager", "config_manager"]
|
68
|
-
)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "returns given value for string" do
|
72
|
-
expect(subject.lib_name).to eq("rdm")
|
73
|
-
end
|
74
|
-
|
75
|
-
it "returns given value for int" do
|
76
|
-
expect(subject.version).to eq(1)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "returns given value for true bool" do
|
80
|
-
expect(subject.published).to eq(true)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "returns given value for false bool" do
|
84
|
-
expect(subject.draft).to eq(false)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "returns given value for array" do
|
88
|
-
expect(subject.features).to eq(["dependency_manager", "config_manager"])
|
89
|
-
end
|
90
|
-
|
91
|
-
it "creates another child scope for nested hash" do
|
92
|
-
expect(subject.database).to be_instance_of(Rdm::ConfigScope)
|
93
|
-
expect(subject.database.username).to eq("foo")
|
94
|
-
expect(subject.database.password).to eq("bar")
|
95
|
-
end
|
96
|
-
|
97
|
-
context "when already has config" do
|
98
|
-
before :each do
|
99
|
-
subject.update_using_hash(
|
100
|
-
database: {
|
101
|
-
username: "new_username",
|
102
|
-
password: "new_password"
|
103
|
-
}
|
104
|
-
)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "keeps old configs" do
|
108
|
-
expect(subject.lib_name).to eq('rdm')
|
109
|
-
end
|
110
|
-
|
111
|
-
it "rewrites new configs" do
|
112
|
-
expect(subject.database.username).to eq('new_username')
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "to_h" do
|
118
|
-
before :each do
|
119
|
-
subject.update_using_hash(
|
120
|
-
site_name: "Sample app",
|
121
|
-
database: {
|
122
|
-
username: "username",
|
123
|
-
password: "password"
|
124
|
-
}
|
125
|
-
)
|
126
|
-
end
|
127
|
-
|
128
|
-
it "returns attributes in root scope" do
|
129
|
-
expect(subject.to_h["site_name"]).to eq("Sample app")
|
130
|
-
end
|
131
|
-
|
132
|
-
it "returns attributes in child scope" do
|
133
|
-
expect(subject.to_h["database"]["username"]).to eq("username")
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
data/spec/rdm/gen/config_spec.rb
DELETED
@@ -1,31 +0,0 @@
|
|
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
|