rdm 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Gemfile.lock +80 -0
- data/bin/rdm +78 -10
- data/example/.rdm/helpers/render_helper.rb +12 -0
- data/example/.rdm/templates/package/.gitignore +1 -0
- data/example/.rdm/templates/package/.rspec +2 -0
- data/example/.rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>.rb +3 -0
- data/example/.rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>/.gitkeep +0 -0
- data/{lib/rdm/templates/package/package.rb.erb → example/.rdm/templates/package/Package.rb} +0 -0
- data/{lib/rdm/templates/package/bin/console_irb → example/.rdm/templates/package/bin/console} +0 -0
- data/example/.rdm/templates/package/spec/spec_helper.rb +10 -0
- data/example/.rdm/templates/repository/dao/<%=name%>_dao.rb +4 -0
- data/example/.rdm/templates/repository/mapper/<%=name%>_mapper.rb +2 -0
- data/example/.rdm/templates/repository/repository/<%=name%>_repository.rb +2 -0
- data/example/.rdm/templates/repository/views/users.html.erb +2 -0
- data/example/Gemfile.lock +50 -0
- data/example/Rdm.packages +1 -0
- data/example/tests/diff_run +0 -0
- data/example/tests/run +0 -0
- data/lib/rdm.rb +40 -8
- data/lib/rdm/cli/compile_package.rb +56 -0
- data/lib/rdm/cli/dependencies_controller.rb +30 -0
- data/lib/rdm/cli/diff_package.rb +21 -0
- data/lib/rdm/cli/gen_package.rb +24 -32
- data/lib/rdm/cli/init.rb +20 -27
- data/lib/rdm/cli/template_generator.rb +38 -0
- data/lib/rdm/errors.rb +37 -0
- data/lib/rdm/gen/init.rb +29 -44
- data/lib/rdm/gen/package.rb +24 -78
- data/lib/rdm/git/diff_command.rb +13 -0
- data/lib/rdm/git/diff_manager.rb +30 -0
- data/lib/rdm/git/repository_locator.rb +23 -0
- data/lib/rdm/handlers/dependencies_handler.rb +110 -0
- data/lib/rdm/handlers/diff_package_handler.rb +48 -0
- data/lib/rdm/handlers/template_handler.rb +118 -0
- data/lib/rdm/helpers/path_helper.rb +15 -0
- data/lib/rdm/package.rb +6 -0
- data/lib/rdm/package_importer.rb +1 -1
- data/lib/rdm/packages/compiler_service.rb +78 -0
- data/lib/rdm/packages/locator.rb +28 -0
- data/lib/rdm/settings.rb +14 -1
- data/lib/rdm/spec_runner.rb +5 -0
- data/lib/rdm/spec_runner/command_generator.rb +28 -0
- data/lib/rdm/spec_runner/command_params.rb +3 -0
- data/lib/rdm/spec_runner/package_fetcher.rb +13 -0
- data/lib/rdm/spec_runner/runner.rb +122 -0
- data/lib/rdm/spec_runner/view.rb +20 -0
- data/lib/rdm/templates/init/.rdm/helpers/render_helper.rb +12 -0
- data/lib/rdm/templates/init/{Gemfile.erb → Gemfile} +0 -0
- data/lib/rdm/templates/init/{Rdm.packages.erb → Rdm.packages} +0 -0
- data/lib/rdm/templates/init/{Readme.md.erb → Readme.md} +0 -0
- data/lib/rdm/templates/init/tests/diff_run +29 -0
- data/lib/rdm/templates/init/tests/run +7 -210
- data/lib/rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>.rb +3 -0
- data/lib/rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>/.gitkeep +0 -0
- data/lib/rdm/templates/package/Package.rb +8 -0
- data/lib/rdm/templates/package/bin/console +16 -0
- data/lib/rdm/templates/template_detector.rb +32 -0
- data/lib/rdm/templates/template_renderer.rb +49 -0
- data/lib/rdm/utils/file_utils.rb +20 -0
- data/lib/rdm/utils/render_util.rb +24 -0
- data/lib/rdm/utils/string_utils.rb +16 -0
- data/lib/rdm/version.rb +1 -1
- data/rdm.gemspec +1 -1
- data/spec/helpers/example_project_helper.rb +217 -0
- data/spec/helpers/git_commands_helper.rb +13 -0
- data/spec/rdm/cli/compile_package_spec.rb +114 -0
- data/spec/rdm/cli/dependencies_controller_spec.rb +50 -0
- data/spec/rdm/cli/diff_package_spec.rb +5 -0
- data/spec/rdm/cli/gen_package_spec.rb +60 -86
- data/spec/rdm/cli/init_spec.rb +53 -70
- data/spec/rdm/gen/init_spec.rb +21 -38
- data/spec/rdm/gen/package_spec.rb +70 -51
- data/spec/rdm/git/diff_manager_spec.rb +81 -0
- data/spec/rdm/git/repository_locator_spec.rb +31 -0
- data/spec/rdm/handlers/dependencies_handler_spec.rb +84 -0
- data/spec/rdm/handlers/diff_package_handler_spec.rb +78 -0
- data/spec/rdm/handlers/template_handler_spec.rb +94 -0
- data/spec/rdm/helpers/path_helper_spec.rb +52 -0
- data/spec/rdm/package/compiler_service_spec.rb +124 -0
- data/spec/rdm/package/locator_spec.rb +31 -0
- data/spec/rdm/rdm_spec.rb +2 -2
- data/spec/rdm/spec_runner/runner_spec.rb +12 -0
- data/spec/rdm/templates/template_detector_spec.rb +39 -0
- data/spec/rdm/templates/template_renderer_spec.rb +42 -0
- data/spec/spec_helper.rb +31 -25
- metadata +84 -17
- data/lib/rdm/gen/concerns/template_handling.rb +0 -81
- data/lib/rdm/support/colorize.rb +0 -106
- data/lib/rdm/support/render.rb +0 -17
- data/lib/rdm/support/template.rb +0 -30
- data/lib/rdm/templates/package/main_module_file.rb.erb +0 -3
- data/spec/rdm/support/colorize_spec.rb +0 -24
- data/spec/rdm/support/template_spec.rb +0 -20
@@ -0,0 +1,30 @@
|
|
1
|
+
module Rdm
|
2
|
+
module CLI
|
3
|
+
class DependenciesController
|
4
|
+
class << self
|
5
|
+
def run(package_name:, project_path:, stdout: nil)
|
6
|
+
new(package_name, project_path, stdout).run
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(package_name, project_path, stdout)
|
11
|
+
@package_name = package_name
|
12
|
+
@project_path = project_path
|
13
|
+
@stdout = stdout || $stdout
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
@stdout.puts Rdm::Handlers::DependenciesHandler.draw(
|
18
|
+
package_name: @package_name,
|
19
|
+
project_path: @project_path
|
20
|
+
)
|
21
|
+
rescue Rdm::Errors::InvalidParams => e
|
22
|
+
@stdout.puts e.message
|
23
|
+
rescue Rdm::Errors::SourceFileDoesNotExist => e
|
24
|
+
@stdout.puts e.message
|
25
|
+
rescue Rdm::Errors::PackageHasNoDependencies => e
|
26
|
+
@stdout.puts "Package `#{e.message}` has no dependencies"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Rdm::CLI::DiffPackage
|
2
|
+
class << self
|
3
|
+
def run(opts = {})
|
4
|
+
Rdm::CLI::DiffPackage.new(opts).run
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :path, :revision
|
9
|
+
def initialize(path:, revision:)
|
10
|
+
@path = path
|
11
|
+
@revision = revision
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
puts Rdm::Handlers::DiffPackageHandler.handle(path: path, revision: revision)
|
16
|
+
rescue Rdm::Errors::GitRepositoryNotInitialized
|
17
|
+
puts "Git repository is not initialized. Use `git init .`"
|
18
|
+
rescue Rdm::Errors::GitCommandError => e
|
19
|
+
puts e.message
|
20
|
+
end
|
21
|
+
end
|
data/lib/rdm/cli/gen_package.rb
CHANGED
@@ -2,46 +2,38 @@ module Rdm
|
|
2
2
|
module CLI
|
3
3
|
class GenPackage
|
4
4
|
class << self
|
5
|
-
def run(
|
6
|
-
Rdm::CLI::GenPackage.new(
|
5
|
+
def run(package_name:, current_path:, local_path:, locals: {}, stdout: $stdout)
|
6
|
+
Rdm::CLI::GenPackage.new(package_name, current_path, local_path, locals, stdout).run
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
@package_name
|
14
|
-
@
|
15
|
-
@
|
10
|
+
def initialize(package_name, current_path, local_path, locals, stdout)
|
11
|
+
@current_path = current_path
|
12
|
+
@local_path = local_path
|
13
|
+
@package_name = package_name
|
14
|
+
@locals = locals
|
15
|
+
@stdout = stdout
|
16
16
|
end
|
17
17
|
|
18
18
|
def run
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
rescue Rdm::Errors::PackageExists
|
25
|
-
puts 'Error. Package already exist. Package was not generated'
|
26
|
-
rescue Rdm::Errors::PackageDirExists
|
27
|
-
puts "Error. Directory #{package_relative_path} exists. Package was not generated"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def generate
|
32
|
-
Rdm::Gen::Package.generate(
|
33
|
-
current_dir: current_dir,
|
34
|
-
package_name: package_name,
|
35
|
-
package_relative_path: package_relative_path,
|
36
|
-
skip_tests: skip_tests
|
19
|
+
generated_files_list = Rdm::Gen::Package.generate(
|
20
|
+
current_path: @current_path,
|
21
|
+
local_path: @local_path,
|
22
|
+
package_name: @package_name,
|
23
|
+
locals: @locals
|
37
24
|
)
|
38
|
-
end
|
39
|
-
|
40
|
-
def check_preconditions!
|
41
|
-
return unless package_name.empty?
|
42
25
|
|
43
|
-
|
44
|
-
|
26
|
+
generated_files_list.each { |file| @stdout.puts "Generated: #{file}" }
|
27
|
+
rescue Errno::ENOENT => e
|
28
|
+
@stdout.puts "Error occurred. Possible reasons:\n #{Rdm::SOURCE_FILENAME} not found. Please run on directory containing #{Rdm::SOURCE_FILENAME} \n#{e.inspect}"
|
29
|
+
rescue Rdm::Errors::PackageExists
|
30
|
+
@stdout.puts 'Error. Package already exist. Package was not generated'
|
31
|
+
rescue Rdm::Errors::PackageNameNotSpecified
|
32
|
+
@stdout.puts "Package name was not specified!"
|
33
|
+
rescue Rdm::Errors::SourceFileDoesNotExist => e
|
34
|
+
@stdout.puts "Rdm.packages was not found. Run 'rdm init' to create it"
|
35
|
+
rescue Rdm::Errors::PackageDirExists => e
|
36
|
+
@stdout.puts "Error. Directory #{e.message} exists. Package was not generated"
|
45
37
|
end
|
46
38
|
end
|
47
39
|
end
|
data/lib/rdm/cli/init.rb
CHANGED
@@ -2,41 +2,34 @@ module Rdm
|
|
2
2
|
module CLI
|
3
3
|
class Init
|
4
4
|
class << self
|
5
|
-
def run(
|
6
|
-
Rdm::CLI::Init.new(
|
5
|
+
def run(current_path:, test:, console:, stdout: $stdout)
|
6
|
+
Rdm::CLI::Init.new(current_path, test, console, stdout).run
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
10
|
+
def initialize(current_path, test, console, stdout)
|
11
|
+
@current_path = current_path
|
12
|
+
@test = test
|
13
|
+
@console = console
|
14
|
+
@stdout = stdout
|
15
15
|
end
|
16
16
|
|
17
17
|
def run
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
puts "Error occurred. Possible reasons:\n #{current_dir} not found. Please run on empty directory \n#{e.inspect}"
|
23
|
-
rescue Rdm::Errors::ProjectAlreadyInitialized
|
24
|
-
puts 'Error. Project was already initialized.'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def generate
|
29
|
-
Rdm::Gen::Init.generate(
|
30
|
-
current_dir: current_dir,
|
31
|
-
test: test,
|
32
|
-
console: console
|
18
|
+
generated_files_list = Rdm::Gen::Init.generate(
|
19
|
+
current_path: @current_path,
|
20
|
+
test: @test,
|
21
|
+
console: @console
|
33
22
|
)
|
34
|
-
end
|
35
23
|
|
36
|
-
|
37
|
-
|
38
|
-
puts
|
39
|
-
|
24
|
+
generated_files_list.each { |file| @stdout.puts "Generated: #{file}" }
|
25
|
+
rescue Errno::ENOENT => e
|
26
|
+
@stdout.puts "Error occurred. Possible reasons:\n #{@current_path} not found. Please run on empty directory \n#{e.inspect}"
|
27
|
+
rescue Rdm::Errors::ProjectAlreadyInitialized
|
28
|
+
@stdout.puts 'Error. Project was already initialized'
|
29
|
+
rescue Rdm::Errors::InvalidParams => e
|
30
|
+
@stdout.puts e.message
|
31
|
+
rescue Rdm::Errors::InvalidProjectDir => e
|
32
|
+
@stdout.puts "#{e.message} doesn't exist. Initialize new rdm project with existing directory"
|
40
33
|
end
|
41
34
|
end
|
42
35
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Rdm
|
2
|
+
module CLI
|
3
|
+
class TemplateGenerator
|
4
|
+
class << self
|
5
|
+
def run(template_name:, current_path:, local_path:, locals:)
|
6
|
+
TemplateGenerator.new(
|
7
|
+
template_name: template_name,
|
8
|
+
current_path: current_path,
|
9
|
+
local_path: local_path,
|
10
|
+
locals: locals
|
11
|
+
).run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(template_name:, current_path:, local_path:, locals:)
|
16
|
+
@template_name = template_name
|
17
|
+
@current_path = current_path
|
18
|
+
@local_path = local_path
|
19
|
+
@locals = locals
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
Rdm::Handlers::TemplateHandler.generate(
|
24
|
+
template_name: @template_name,
|
25
|
+
current_path: @current_path,
|
26
|
+
local_path: @local_path,
|
27
|
+
locals: @locals
|
28
|
+
)
|
29
|
+
rescue Rdm::Errors::TemplateDoesNotExist
|
30
|
+
puts "Template '#{@template_name}' does not exist. Create new at #{File.join(@current_path, '.rdm/templates/', @template_name)} folder"
|
31
|
+
rescue Rdm::Errors::SourceFileDoesNotExist => e
|
32
|
+
puts e.message
|
33
|
+
rescue Rdm::Errors::TemplateFileExists => e
|
34
|
+
puts "File #{e.message} already exists. Try to user another variable name"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/rdm/errors.rb
CHANGED
@@ -9,6 +9,43 @@ module Rdm
|
|
9
9
|
end
|
10
10
|
|
11
11
|
class SourceFileDoesNotExist < StandardError
|
12
|
+
attr_reader :message
|
13
|
+
def initialize(message = nil)
|
14
|
+
@message = message || "Rdm.packages was not found. Run 'rdm init' to create it"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class GitRepositoryNotInitialized < StandardError
|
19
|
+
end
|
20
|
+
|
21
|
+
class PackageFileDoesNotFound < StandardError
|
22
|
+
end
|
23
|
+
|
24
|
+
class GitCommandError < StandardError
|
25
|
+
end
|
26
|
+
|
27
|
+
class PackageDoesNotExist < StandardError
|
28
|
+
end
|
29
|
+
|
30
|
+
class TemplateVariableNotDefined < StandardError
|
31
|
+
end
|
32
|
+
|
33
|
+
class TemplateDoesNotExist < StandardError
|
34
|
+
end
|
35
|
+
|
36
|
+
class TemplateFileExists < StandardError
|
37
|
+
end
|
38
|
+
|
39
|
+
class PackageNameNotSpecified < StandardError
|
40
|
+
end
|
41
|
+
|
42
|
+
class InvalidParams < StandardError
|
43
|
+
end
|
44
|
+
|
45
|
+
class InvalidProjectDir < StandardError
|
46
|
+
end
|
47
|
+
|
48
|
+
class PackageHasNoDependencies < StandardError
|
12
49
|
end
|
13
50
|
end
|
14
51
|
end
|
data/lib/rdm/gen/init.rb
CHANGED
@@ -1,68 +1,53 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'pathname'
|
3
|
-
require 'active_support/inflector'
|
4
3
|
|
5
4
|
module Rdm
|
6
5
|
module Gen
|
7
6
|
class Init
|
7
|
+
TEMPLATE_NAME = 'init'
|
8
|
+
INIT_PATH = './'
|
9
|
+
LOCAL_TEMPLATES_PATH = '.rdm/templates'
|
10
|
+
|
8
11
|
class << self
|
9
|
-
def generate(
|
10
|
-
Rdm::Gen::Init.new(
|
12
|
+
def generate(current_path:, test: 'rspec', console: 'irb')
|
13
|
+
Rdm::Gen::Init.new(current_path, test, console).generate
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@
|
19
|
-
@test = test
|
20
|
-
@console = console
|
17
|
+
def initialize(current_path, test, console)
|
18
|
+
@current_path = current_path
|
19
|
+
@test = test
|
20
|
+
@console = console
|
21
|
+
@template_detector = Rdm::Templates::TemplateDetector.new(current_path)
|
21
22
|
end
|
22
23
|
|
23
24
|
def generate
|
24
|
-
|
25
|
-
|
26
|
-
Dir.chdir(current_dir) do
|
27
|
-
ensure_file(['.gitignore'])
|
28
|
-
ensure_file(
|
29
|
-
['Rdm.packages'],
|
30
|
-
template_content('Rdm.packages.erb')
|
31
|
-
)
|
32
|
-
|
33
|
-
ensure_file(
|
34
|
-
['Gemfile'],
|
35
|
-
template_content('Gemfile.erb')
|
36
|
-
)
|
37
|
-
|
38
|
-
ensure_file(
|
39
|
-
['Readme.md'],
|
40
|
-
template_content('Readme.md.erb')
|
41
|
-
)
|
42
|
-
move_templates
|
25
|
+
if @current_path.nil? || @current_path.empty?
|
26
|
+
raise Rdm::Errors::InvalidParams, "Error. Project folder not specified. Type path to rdm project, ex: 'rdm init .'"
|
43
27
|
end
|
44
|
-
|
28
|
+
raise Rdm::Errors::InvalidProjectDir, @current_path unless Dir.exist?(@current_path)
|
45
29
|
|
46
|
-
|
47
|
-
|
48
|
-
raise Rdm::Errors::ProjectAlreadyInitialized, "#{current_dir} has already #{Rdm::SOURCE_FILENAME}"
|
30
|
+
if File.exist?(File.join(@current_path, Rdm::SOURCE_FILENAME))
|
31
|
+
raise Rdm::Errors::ProjectAlreadyInitialized, "#{@current_path} has already #{Rdm::SOURCE_FILENAME}"
|
49
32
|
end
|
50
|
-
end
|
51
33
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
34
|
+
FileUtils.mkdir_p(local_templates_path)
|
35
|
+
FileUtils.cp_r(
|
36
|
+
@template_detector.detect_template_folder('package'),
|
37
|
+
local_templates_path
|
38
|
+
)
|
39
|
+
Rdm::Handlers::TemplateHandler.generate(
|
40
|
+
template_name: TEMPLATE_NAME,
|
41
|
+
current_path: @current_path,
|
42
|
+
local_path: INIT_PATH,
|
43
|
+
ignore_source_file: true
|
44
|
+
)
|
56
45
|
end
|
57
46
|
|
58
47
|
private
|
59
48
|
|
60
|
-
def
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
def target_path
|
65
|
-
current_dir
|
49
|
+
def local_templates_path
|
50
|
+
File.join(@current_path, LOCAL_TEMPLATES_PATH)
|
66
51
|
end
|
67
52
|
end
|
68
53
|
end
|
data/lib/rdm/gen/package.rb
CHANGED
@@ -1,98 +1,44 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'pathname'
|
3
|
-
require 'active_support/inflector'
|
4
3
|
|
5
4
|
module Rdm
|
6
5
|
module Gen
|
7
6
|
class Package
|
7
|
+
TEMPLATE_NAME = 'package'
|
8
|
+
|
8
9
|
class << self
|
9
|
-
def generate(
|
10
|
-
Rdm::Gen::Package.new(
|
11
|
-
current_dir, package_name, package_relative_path, skip_tests
|
12
|
-
).create
|
10
|
+
def generate(package_name:, current_path:, local_path:, locals: {})
|
11
|
+
Rdm::Gen::Package.new(package_name, current_path, local_path, locals).create
|
13
12
|
end
|
14
13
|
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@
|
21
|
-
@package_name = package_name
|
22
|
-
@package_relative_path = package_relative_path
|
23
|
-
@skip_tests = skip_tests
|
24
|
-
end
|
25
|
-
|
26
|
-
def rdm_source
|
27
|
-
@rdm_source ||= Rdm::SourceParser.new(source_path).parse_source_content
|
28
|
-
end
|
29
|
-
|
30
|
-
def source_path
|
31
|
-
File.join(current_dir, Rdm::SOURCE_FILENAME)
|
32
|
-
end
|
33
|
-
|
34
|
-
def source_content
|
35
|
-
File.open(source_path).read
|
15
|
+
def initialize(package_name, current_path, local_path, locals = {})
|
16
|
+
@current_path = current_path
|
17
|
+
@package_name = package_name
|
18
|
+
@local_path = local_path
|
19
|
+
@locals = locals
|
36
20
|
end
|
37
21
|
|
38
22
|
def create
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
Dir.chdir(current_dir) do
|
43
|
-
ensure_file([package_relative_path, '.gitignore'])
|
44
|
-
ensure_file([package_relative_path, package_subdir_name, package_name, '.gitignore'])
|
45
|
-
ensure_file(
|
46
|
-
[package_relative_path, package_subdir_name, "#{package_name}.rb"],
|
47
|
-
template_content('main_module_file.rb.erb', package_name_camelized: package_name.camelize)
|
48
|
-
)
|
49
|
-
ensure_file(
|
50
|
-
[package_relative_path, 'Package.rb'],
|
51
|
-
template_content('package.rb.erb', package_name: package_name)
|
52
|
-
)
|
53
|
-
init_rspec unless skip_tests
|
54
|
-
|
55
|
-
move_templates
|
56
|
-
append_package_to_rdm_packages
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def check_preconditions!
|
61
|
-
if Dir.exist?(File.join(current_dir, package_relative_path))
|
62
|
-
raise Rdm::Errors::PackageDirExists, 'package dir exists'
|
63
|
-
end
|
64
|
-
|
65
|
-
if rdm_source.package_paths.include?(package_relative_path)
|
66
|
-
raise Rdm::Errors::PackageExists, 'package exists'
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def append_package_to_rdm_packages
|
71
|
-
new_source_content = source_content.strip + "\npackage '#{package_relative_path}'"
|
72
|
-
File.write(source_path, new_source_content)
|
73
|
-
end
|
74
|
-
|
75
|
-
def init_rspec
|
76
|
-
Dir.chdir(templates_path) do
|
77
|
-
copy_template('.rspec')
|
78
|
-
copy_template('spec/spec_helper.rb')
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def move_templates
|
83
|
-
Dir.chdir(templates_path) do
|
84
|
-
copy_template('bin/console_irb', 'bin/console')
|
85
|
-
end
|
86
|
-
end
|
23
|
+
raise Rdm::Errors::PackageDirExists.new(@local_path) if Dir.exist?(File.join(source.root_path, @local_path))
|
24
|
+
raise Rdm::Errors::PackageNameNotSpecified if @package_name.nil? || @package_name.empty?
|
25
|
+
raise Rdm::Errors::PackageExists if source.packages.keys.include?(@package_name)
|
87
26
|
|
88
|
-
|
27
|
+
File.open(File.join(source.root_path, Rdm::SOURCE_FILENAME), 'a+') {|f| f.write("package '#{@local_path}'")}
|
89
28
|
|
90
|
-
|
91
|
-
|
29
|
+
Rdm::Handlers::TemplateHandler.generate(
|
30
|
+
template_name: TEMPLATE_NAME,
|
31
|
+
current_path: @current_path,
|
32
|
+
local_path: @local_path,
|
33
|
+
locals: {
|
34
|
+
package_name: @package_name,
|
35
|
+
package_name_camelized: Rdm::Utils::StringUtils.camelize(@package_name)
|
36
|
+
}.merge(@locals)
|
37
|
+
)
|
92
38
|
end
|
93
39
|
|
94
|
-
def
|
95
|
-
|
40
|
+
def source
|
41
|
+
@source ||= Rdm::SourceParser.read_and_init_source(Rdm::SourceLocator.locate(@current_path))
|
96
42
|
end
|
97
43
|
end
|
98
44
|
end
|