rdm 0.1.12 → 0.1.13
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.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.rubocop.yml +17 -0
- data/.travis.yml +13 -0
- data/Gemfile +5 -1
- data/LICENSE.txt +1 -1
- data/README.md +84 -28
- data/bin/rdm +72 -0
- data/bin/rubocop +6 -0
- data/docs/_config.yml +1 -0
- data/docs/index.md +98 -0
- data/docs/interface_brainstorming.md +31 -0
- data/example/Rdm.packages +1 -1
- data/example/Readme.md +1 -3
- data/lib/rdm.rb +29 -20
- data/lib/rdm/cli/gen_package.rb +48 -0
- data/lib/rdm/cli/init.rb +43 -0
- data/lib/rdm/config.rb +9 -1
- data/lib/rdm/config_manager.rb +5 -5
- data/lib/rdm/config_scope.rb +3 -3
- data/lib/rdm/errors.rb +2 -0
- data/lib/rdm/gen/concerns/template_handling.rb +81 -0
- data/lib/rdm/gen/init.rb +69 -0
- data/lib/rdm/gen/package.rb +99 -0
- data/lib/rdm/package.rb +17 -16
- data/lib/rdm/package_importer.rb +89 -79
- data/lib/rdm/package_parser.rb +25 -5
- data/lib/rdm/settings.rb +21 -20
- data/lib/rdm/source.rb +1 -1
- data/lib/rdm/source_locator.rb +31 -0
- data/lib/rdm/source_parser.rb +83 -68
- data/lib/rdm/support/colorize.rb +106 -0
- data/lib/rdm/support/render.rb +17 -0
- data/lib/rdm/support/template.rb +30 -0
- data/lib/rdm/templates/init/Gemfile.erb +25 -0
- data/lib/rdm/templates/init/Rdm.packages.erb +18 -0
- data/lib/rdm/templates/init/Readme.md.erb +24 -0
- data/lib/rdm/templates/{tests → init/tests}/run +27 -31
- data/lib/rdm/templates/package/.gitignore +1 -0
- data/lib/rdm/templates/{.rspec → package/.rspec} +0 -0
- data/lib/rdm/templates/{bin → package/bin}/console_irb +4 -5
- data/lib/rdm/templates/{main_module_file.rb.erb → package/main_module_file.rb.erb} +0 -0
- data/lib/rdm/templates/{package.rb.erb → package/package.rb.erb} +0 -0
- data/lib/rdm/templates/{spec → package/spec}/spec_helper.rb +0 -0
- data/lib/rdm/version.rb +1 -1
- data/rdm.gemspec +3 -0
- data/spec/fixtures/SampleSource.rb +3 -1
- data/spec/fixtures/sample_prj/Rdm.packages +12 -0
- data/spec/fixtures/sample_prj/infrastructure/web/Package.rb +16 -0
- data/spec/rdm/cli/gen_package_spec.rb +130 -0
- data/spec/rdm/cli/init_spec.rb +97 -0
- data/spec/rdm/config_manager_spec.rb +37 -1
- data/spec/rdm/gen/init_spec.rb +63 -0
- data/spec/rdm/gen/package_spec.rb +87 -0
- data/spec/rdm/package_importer_spec.rb +5 -1
- data/spec/rdm/package_parser_spec.rb +10 -24
- data/spec/rdm/rdm_spec.rb +42 -0
- data/spec/rdm/source_locator_spec.rb +45 -0
- data/spec/rdm/source_parser_spec.rb +45 -3
- data/spec/rdm/support/colorize_spec.rb +24 -0
- data/spec/rdm/support/template_spec.rb +20 -0
- data/spec/spec_helper.rb +45 -0
- metadata +92 -16
- data/bin/rdm-generate +0 -55
- data/bin/rdm-install +0 -13
- data/lib/rdm/auto_updater.rb +0 -41
- data/lib/rdm/package_generator.rb +0 -121
- data/lib/rdm/source_installer.rb +0 -35
- data/lib/rdm/templates/.gitignore +0 -1
@@ -0,0 +1,130 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rdm::CLI::GenPackage do
|
4
|
+
include SetupHelper
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
Rdm::Gen::Package.disable_logger!
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_project!
|
11
|
+
Rdm::Gen::Init.generate(
|
12
|
+
current_dir: empty_project_dir
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def ensure_exists(file)
|
17
|
+
expect(File.exists?(file)).to be true
|
18
|
+
end
|
19
|
+
|
20
|
+
def ensure_content(file, content)
|
21
|
+
expect(File.read(file)).to match(content)
|
22
|
+
end
|
23
|
+
|
24
|
+
context "run" do
|
25
|
+
before :all do
|
26
|
+
fresh_project
|
27
|
+
end
|
28
|
+
|
29
|
+
after :all do
|
30
|
+
clean_tmp
|
31
|
+
end
|
32
|
+
|
33
|
+
it "generates package" do
|
34
|
+
opts = {
|
35
|
+
package_name: "database",
|
36
|
+
current_dir: project_dir,
|
37
|
+
path: "infrastructure/database" ,
|
38
|
+
skip_tests: false
|
39
|
+
}
|
40
|
+
Rdm::CLI::GenPackage.run(opts)
|
41
|
+
|
42
|
+
FileUtils.cd(project_dir) do
|
43
|
+
ensure_exists("infrastructure/database/Package.rb")
|
44
|
+
ensure_exists("infrastructure/database/package/database.rb")
|
45
|
+
ensure_exists("infrastructure/database/package/database/")
|
46
|
+
ensure_exists("infrastructure/database/bin/console")
|
47
|
+
ensure_exists("infrastructure/database/spec/spec_helper.rb")
|
48
|
+
ensure_exists("infrastructure/database/.rspec")
|
49
|
+
ensure_exists("infrastructure/database/.gitignore")
|
50
|
+
ensure_content("infrastructure/database/package/database.rb", "module Database\n\nend\n")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "run with errors" do
|
56
|
+
before :all do
|
57
|
+
clean_tmp
|
58
|
+
end
|
59
|
+
|
60
|
+
after :all do
|
61
|
+
clean_tmp
|
62
|
+
end
|
63
|
+
|
64
|
+
it "fails when in wrong directory" do
|
65
|
+
opts = {
|
66
|
+
package_name: "database",
|
67
|
+
current_dir: project_dir,
|
68
|
+
path: "infrastructure/database" ,
|
69
|
+
skip_tests: false
|
70
|
+
}
|
71
|
+
|
72
|
+
expect{
|
73
|
+
Rdm::CLI::GenPackage.run(opts)
|
74
|
+
}.to output(/Rdm.packages\ not\ found/).to_stdout
|
75
|
+
end
|
76
|
+
|
77
|
+
it "fails when package already created" do
|
78
|
+
fresh_project
|
79
|
+
opts = {
|
80
|
+
package_name: "database",
|
81
|
+
current_dir: project_dir,
|
82
|
+
path: "infrastructure/database" ,
|
83
|
+
skip_tests: false
|
84
|
+
}
|
85
|
+
Rdm::CLI::GenPackage.run(opts)
|
86
|
+
|
87
|
+
expect{
|
88
|
+
Rdm::CLI::GenPackage.run(opts)
|
89
|
+
}.to output(Regexp.new("Error. Directory infrastructure/database exists. Package was not generated")).to_stdout
|
90
|
+
clean_tmp
|
91
|
+
end
|
92
|
+
|
93
|
+
it "fails when package already created" do
|
94
|
+
fresh_project
|
95
|
+
opts = {
|
96
|
+
package_name: "database",
|
97
|
+
current_dir: project_dir,
|
98
|
+
path: "infrastructure/database" ,
|
99
|
+
skip_tests: false
|
100
|
+
}
|
101
|
+
Rdm::CLI::GenPackage.run(opts)
|
102
|
+
|
103
|
+
FileUtils.rm_rf(File.join(project_dir, "infrastructure/database"))
|
104
|
+
|
105
|
+
expect{
|
106
|
+
Rdm::CLI::GenPackage.run(opts)
|
107
|
+
}.to output(Regexp.new("Error. Package already exist. Package was not generated")).to_stdout
|
108
|
+
clean_tmp
|
109
|
+
end
|
110
|
+
|
111
|
+
it "fails when empty package given" do
|
112
|
+
fresh_project
|
113
|
+
opts = {
|
114
|
+
package_name: "",
|
115
|
+
current_dir: project_dir,
|
116
|
+
path: "infrastructure/database" ,
|
117
|
+
skip_tests: false
|
118
|
+
}
|
119
|
+
begin
|
120
|
+
expect{
|
121
|
+
Rdm::CLI::GenPackage.run(opts)
|
122
|
+
}.to output(Regexp.new("Package name was not specified!")).to_stdout
|
123
|
+
rescue SystemExit
|
124
|
+
clean_tmp
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rdm::CLI::Init do
|
4
|
+
include SetupHelper
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
Rdm::Gen::Init.disable_logger!
|
8
|
+
end
|
9
|
+
|
10
|
+
def ensure_exists(file)
|
11
|
+
expect(File.exists?(file)).to be true
|
12
|
+
end
|
13
|
+
|
14
|
+
def ensure_content(file, content)
|
15
|
+
expect(File.read(file)).to match(content)
|
16
|
+
end
|
17
|
+
|
18
|
+
context "run" do
|
19
|
+
before :all do
|
20
|
+
fresh_empty_project
|
21
|
+
end
|
22
|
+
|
23
|
+
after :all do
|
24
|
+
clean_tmp
|
25
|
+
end
|
26
|
+
|
27
|
+
it "generates package" do
|
28
|
+
opts = {
|
29
|
+
current_dir: empty_project_dir,
|
30
|
+
console: "irb",
|
31
|
+
test: "rspec"
|
32
|
+
}
|
33
|
+
Rdm::CLI::Init.run(opts)
|
34
|
+
|
35
|
+
FileUtils.cd(empty_project_dir) do
|
36
|
+
ensure_exists("Rdm.packages")
|
37
|
+
ensure_exists("Gemfile")
|
38
|
+
ensure_exists("Readme.md")
|
39
|
+
ensure_exists("tests/run")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "run with errors" do
|
45
|
+
before :all do
|
46
|
+
clean_tmp
|
47
|
+
end
|
48
|
+
|
49
|
+
after :all do
|
50
|
+
clean_tmp
|
51
|
+
end
|
52
|
+
|
53
|
+
it "fails when in wrong directory" do
|
54
|
+
opts = {
|
55
|
+
current_dir: empty_project_dir + "/not-there",
|
56
|
+
console: "irb",
|
57
|
+
test: "rspec"
|
58
|
+
}
|
59
|
+
|
60
|
+
expect{
|
61
|
+
Rdm::CLI::Init.run(opts)
|
62
|
+
}.to output(Regexp.new("Please run on empty directory")).to_stdout
|
63
|
+
end
|
64
|
+
|
65
|
+
it "fails when project already initialized" do
|
66
|
+
fresh_empty_project
|
67
|
+
opts = {
|
68
|
+
current_dir: empty_project_dir,
|
69
|
+
console: "irb",
|
70
|
+
test: "rspec"
|
71
|
+
}
|
72
|
+
Rdm::CLI::Init.run(opts)
|
73
|
+
|
74
|
+
expect{
|
75
|
+
Rdm::CLI::Init.run(opts)
|
76
|
+
}.to output(Regexp.new("Error. Project was already initialized")).to_stdout
|
77
|
+
clean_tmp
|
78
|
+
end
|
79
|
+
|
80
|
+
it "fails with wrong current_dir and exits" do
|
81
|
+
opts = {
|
82
|
+
current_dir: "",
|
83
|
+
console: "irb",
|
84
|
+
test: "rspec"
|
85
|
+
}
|
86
|
+
|
87
|
+
a = 0
|
88
|
+
begin
|
89
|
+
a = 1
|
90
|
+
Rdm::CLI::Init.run(opts)
|
91
|
+
a = 2
|
92
|
+
rescue SystemExit
|
93
|
+
expect(a).to eq(1)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -3,6 +3,42 @@ require 'spec_helper'
|
|
3
3
|
describe Rdm::ConfigManager do
|
4
4
|
subject { Rdm::ConfigManager.new }
|
5
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
|
+
|
6
42
|
describe "#update_using_file" do
|
7
43
|
let(:fixtures_path) {
|
8
44
|
File.join(File.expand_path("../../", __FILE__), 'fixtures')
|
@@ -97,4 +133,4 @@ describe Rdm::ConfigManager do
|
|
97
133
|
expect(subject.to_h["database"]["username"]).to eq("username")
|
98
134
|
end
|
99
135
|
end
|
100
|
-
end
|
136
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rdm::Gen::Init do
|
4
|
+
include SetupHelper
|
5
|
+
|
6
|
+
def generate_project!
|
7
|
+
Rdm::Gen::Init.generate(
|
8
|
+
current_dir: empty_project_dir
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
def ensure_exists(file)
|
13
|
+
expect(File.exists?(file)).to be true
|
14
|
+
end
|
15
|
+
|
16
|
+
def ensure_content(file, content)
|
17
|
+
expect(File.read(file)).to match(content)
|
18
|
+
end
|
19
|
+
|
20
|
+
context "sample project" do
|
21
|
+
before :all do
|
22
|
+
Rdm::Gen::Init.disable_logger!
|
23
|
+
fresh_empty_project
|
24
|
+
generate_project!
|
25
|
+
end
|
26
|
+
|
27
|
+
after :all do
|
28
|
+
clean_tmp
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has generated correct files" do
|
32
|
+
FileUtils.cd(empty_project_dir) do
|
33
|
+
ensure_exists("Rdm.packages")
|
34
|
+
ensure_exists("Gemfile")
|
35
|
+
ensure_exists("Readme.md")
|
36
|
+
ensure_exists("tests/run")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has logged useful output" do
|
41
|
+
Rdm::Gen::Init.enable_logger!
|
42
|
+
expect {
|
43
|
+
fresh_empty_project
|
44
|
+
generate_project!
|
45
|
+
}.to output(/Generated: Rdm.packages/).to_stdout
|
46
|
+
Rdm::Gen::Init.disable_logger!
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "prevents double execution" do
|
51
|
+
after :all do
|
52
|
+
clean_tmp
|
53
|
+
end
|
54
|
+
|
55
|
+
it "raises on second project generation" do
|
56
|
+
fresh_empty_project
|
57
|
+
generate_project!
|
58
|
+
expect {
|
59
|
+
generate_project!
|
60
|
+
}.to raise_error(Rdm::Errors::ProjectAlreadyInitialized)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rdm::Gen::Package do
|
4
|
+
before :all do
|
5
|
+
Rdm::Gen::Package.disable_logger!
|
6
|
+
end
|
7
|
+
include SetupHelper
|
8
|
+
|
9
|
+
def generate_package!
|
10
|
+
Rdm::Gen::Package.generate(
|
11
|
+
current_dir: project_dir,
|
12
|
+
package_name: "some",
|
13
|
+
package_relative_path: "domain/some",
|
14
|
+
skip_tests: false
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def ensure_exists(file)
|
19
|
+
expect(File.exists?(file)).to be true
|
20
|
+
end
|
21
|
+
|
22
|
+
def ensure_content(file, content)
|
23
|
+
expect(File.read(file)).to match(content)
|
24
|
+
end
|
25
|
+
|
26
|
+
context "sample package" do
|
27
|
+
before :all do
|
28
|
+
fresh_project
|
29
|
+
generate_package!
|
30
|
+
end
|
31
|
+
|
32
|
+
after :all do
|
33
|
+
clean_tmp
|
34
|
+
end
|
35
|
+
|
36
|
+
it "has generated correct files" do
|
37
|
+
FileUtils.cd(project_dir) do
|
38
|
+
ensure_exists("domain/some/Package.rb")
|
39
|
+
ensure_exists("domain/some/package/some.rb")
|
40
|
+
ensure_exists("domain/some/package/some/")
|
41
|
+
ensure_exists("domain/some/bin/console")
|
42
|
+
ensure_exists("domain/some/spec/spec_helper.rb")
|
43
|
+
ensure_exists("domain/some/.rspec")
|
44
|
+
ensure_exists("domain/some/.gitignore")
|
45
|
+
ensure_content("domain/some/package/some.rb", "module Some\n\nend\n")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "has added new entry to Rdm.packages" do
|
50
|
+
FileUtils.cd(project_dir) do
|
51
|
+
ensure_content("Rdm.packages", "package 'domain/some'")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it "has logged useful output" do
|
56
|
+
Rdm::Gen::Package.enable_logger!
|
57
|
+
expect {
|
58
|
+
fresh_project
|
59
|
+
generate_package!
|
60
|
+
}.to output(Regexp.new("Generated: domain/some/Package.rb")).to_stdout
|
61
|
+
Rdm::Gen::Package.disable_logger!
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "prevents double execution" do
|
66
|
+
after :all do
|
67
|
+
clean_tmp
|
68
|
+
end
|
69
|
+
|
70
|
+
it "raises on second package generation" do
|
71
|
+
fresh_project
|
72
|
+
generate_package!
|
73
|
+
expect {
|
74
|
+
generate_package!
|
75
|
+
}.to raise_error(Rdm::Errors::PackageDirExists)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "raises on second package generation, if Rdm.packages includes the package (and folder does not exist)" do
|
79
|
+
fresh_project
|
80
|
+
generate_package!
|
81
|
+
FileUtils.rm_rf(File.join(project_dir, "domain/some"))
|
82
|
+
expect {
|
83
|
+
generate_package!
|
84
|
+
}.to raise_error(Rdm::Errors::PackageExists)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -17,6 +17,10 @@ describe Rdm::PackageImporter do
|
|
17
17
|
source
|
18
18
|
end
|
19
19
|
|
20
|
+
before do
|
21
|
+
Rdm::PackageImporter.reset!
|
22
|
+
end
|
23
|
+
|
20
24
|
describe "#import_package" do
|
21
25
|
subject { Rdm::PackageImporter }
|
22
26
|
|
@@ -61,4 +65,4 @@ describe Rdm::PackageImporter do
|
|
61
65
|
end
|
62
66
|
end
|
63
67
|
end
|
64
|
-
end
|
68
|
+
end
|