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
data/bin/rdm-generate
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*- encoding: utf-8 -*-
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'bundler'
|
6
|
-
Bundler.setup
|
7
|
-
require 'rdm'
|
8
|
-
require 'optparse'
|
9
|
-
|
10
|
-
current_dir = `pwd`.chomp
|
11
|
-
|
12
|
-
options = {
|
13
|
-
skip_rspec: false
|
14
|
-
}
|
15
|
-
|
16
|
-
if ARGV[0] != 'package'
|
17
|
-
puts "Unsupported generator command provided. Please use `rdm-generate package PACKAGE_NAME args`."
|
18
|
-
exit 1
|
19
|
-
end
|
20
|
-
|
21
|
-
package_name = ARGV[1].to_s.strip
|
22
|
-
if package_name.empty?
|
23
|
-
puts 'Package name was not specified'
|
24
|
-
exit 1
|
25
|
-
end
|
26
|
-
|
27
|
-
OptionParser.new do |opts|
|
28
|
-
opts.banner = "Usage: rdm-generate package PACKAGE_NAME --path=RELATIVE_PATH --skip-rspec"
|
29
|
-
|
30
|
-
opts.on('--skip-rspec', 'Skip rspec generation') do
|
31
|
-
options[:skip_rspec] = true
|
32
|
-
end
|
33
|
-
|
34
|
-
opts.on('--path=', '', 'Package relative path') do |v|
|
35
|
-
options[:path] = v.strip
|
36
|
-
end
|
37
|
-
end.parse!
|
38
|
-
|
39
|
-
if options[:path].nil?
|
40
|
-
options[:path] = package_name.downcase.gsub(/\s+/, '_')
|
41
|
-
end
|
42
|
-
|
43
|
-
options[:path].gsub!(/^\/+/, '')
|
44
|
-
|
45
|
-
puts "Generating package #{package_name} to #{options[:path]}"
|
46
|
-
|
47
|
-
begin
|
48
|
-
Rdm::PackageGenerator.generate_package(current_dir, package_name, options[:path], options[:skip_rspec])
|
49
|
-
rescue Errno::ENOENT => e
|
50
|
-
puts "Error occurred. Possible reasons:\n #{Rdm::SOURCE_FILENAME} not found. Please run on directory containing #{Rdm::SOURCE_FILENAME} \n#{e.inspect}"
|
51
|
-
rescue Rdm::Errors::PackageExists
|
52
|
-
puts "Error. Package already exist. Package was not generated"
|
53
|
-
rescue Rdm::Errors::PackageDirExists
|
54
|
-
puts "Error. Directory #{options[:path]} exists. Package was not generated"
|
55
|
-
end
|
data/bin/rdm-install
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*- encoding: utf-8 -*-
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'bundler'
|
6
|
-
require 'rdm'
|
7
|
-
|
8
|
-
source_path = File.join(`pwd`.chomp, Rdm::SOURCE_FILENAME)
|
9
|
-
begin
|
10
|
-
Rdm::SourceInstaller.install(source_path)
|
11
|
-
rescue Errno::ENOENT => e
|
12
|
-
puts "Error occurred. Possible reasons:\n #{Rdm::SOURCE_FILENAME} not found. Please run on directory containing #{Rdm::SOURCE_FILENAME} \n#{e.inspect}"
|
13
|
-
end
|
data/lib/rdm/auto_updater.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
module Rdm
|
2
|
-
class AutoUpdater
|
3
|
-
class << self
|
4
|
-
def update(path)
|
5
|
-
Rdm::AutoUpdater.new(path).update
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
attr_accessor :path
|
10
|
-
def initialize(path)
|
11
|
-
@path = path
|
12
|
-
end
|
13
|
-
|
14
|
-
def update
|
15
|
-
begin
|
16
|
-
source_path = find_source_path_in_hierarchy(path)
|
17
|
-
Rdm::SourceInstaller.install(source_path)
|
18
|
-
rescue Rdm::Errors::SourceFileDoesNotExist => e
|
19
|
-
puts "*** #{path} does not include any #{Rdm::SOURCE_FILENAME} in its tree hierarchy!"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def find_source_path_in_hierarchy(some_path)
|
24
|
-
some_path = File.expand_path(some_path)
|
25
|
-
raise SourceFileDoesNotExist if some_path == "/"
|
26
|
-
if is_present?(some_path)
|
27
|
-
return potential_file(some_path)
|
28
|
-
else
|
29
|
-
find_source_path_in_hierarchy(File.dirname(some_path))
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def is_present?(some_path)
|
34
|
-
File.exists?(potential_file(some_path))
|
35
|
-
end
|
36
|
-
|
37
|
-
def potential_file(some_path)
|
38
|
-
File.join(some_path, Rdm::SOURCE_FILENAME)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'pathname'
|
3
|
-
require "active_support/inflector"
|
4
|
-
|
5
|
-
|
6
|
-
# http://stackoverflow.com/questions/8954706/render-an-erb-template-with-values-from-a-hash
|
7
|
-
require 'erb'
|
8
|
-
require 'ostruct'
|
9
|
-
class ErbalT < OpenStruct
|
10
|
-
def self.render(template, locals)
|
11
|
-
self.new(locals).render(template)
|
12
|
-
end
|
13
|
-
def render(template)
|
14
|
-
ERB.new(template).result(binding)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
class Rdm::PackageGenerator
|
20
|
-
class << self
|
21
|
-
def generate_package(current_dir, package_name, package_relative_path, skip_rspec = false)
|
22
|
-
Rdm::PackageGenerator.new(
|
23
|
-
current_dir, package_name, package_relative_path, skip_rspec
|
24
|
-
).create
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
attr_accessor :current_dir, :package_name, :package_relative_path, :skip_rspec
|
29
|
-
def initialize(current_dir, package_name, package_relative_path, skip_rspec = false)
|
30
|
-
@current_dir = current_dir
|
31
|
-
@package_name = package_name
|
32
|
-
@package_relative_path = package_relative_path
|
33
|
-
@skip_rspec = skip_rspec
|
34
|
-
end
|
35
|
-
|
36
|
-
def rdm_source
|
37
|
-
@rdm_source ||= Rdm::SourceParser.parse(source_content)
|
38
|
-
end
|
39
|
-
def source_path
|
40
|
-
File.join(current_dir, Rdm::SOURCE_FILENAME)
|
41
|
-
end
|
42
|
-
def source_content
|
43
|
-
File.open(source_path).read
|
44
|
-
end
|
45
|
-
|
46
|
-
def create
|
47
|
-
check_preconditions!
|
48
|
-
package_subdir_name = Rdm.settings.send(:package_subdir_name)
|
49
|
-
|
50
|
-
Dir.chdir(current_dir) do
|
51
|
-
ensure_file([package_relative_path, '.gitignore'])
|
52
|
-
ensure_file([package_relative_path, package_subdir_name, package_name, '.gitignore'])
|
53
|
-
ensure_file(
|
54
|
-
[package_relative_path, package_subdir_name, "#{package_name}.rb"],
|
55
|
-
template_content("main_module_file.rb.erb", {package_name_camelized: package_name.camelize})
|
56
|
-
)
|
57
|
-
ensure_file(
|
58
|
-
[package_relative_path, 'Package.rb'],
|
59
|
-
template_content("package.rb.erb", {package_name: package_name})
|
60
|
-
)
|
61
|
-
if !skip_rspec
|
62
|
-
init_rspec
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
move_templates
|
67
|
-
append_package_to_rdm_packages
|
68
|
-
end
|
69
|
-
|
70
|
-
def check_preconditions!
|
71
|
-
if Dir.exist?(File.join(current_dir, package_relative_path))
|
72
|
-
raise Rdm::Errors::PackageDirExists, "package dir exists"
|
73
|
-
end
|
74
|
-
|
75
|
-
if rdm_source.package_paths.include?(package_relative_path)
|
76
|
-
raise Rdm::Errors::PackageExists, "package exists"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def append_package_to_rdm_packages
|
81
|
-
new_source_content = source_content + "\npackage '#{package_relative_path}'"
|
82
|
-
File.write(source_path, new_source_content)
|
83
|
-
end
|
84
|
-
|
85
|
-
def init_rspec
|
86
|
-
FileUtils.cd(File.join(package_relative_path)) do
|
87
|
-
system('rspec --init')
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def move_templates
|
92
|
-
Dir.chdir(File.join(File.dirname(__FILE__), "templates")) do
|
93
|
-
copy_template(".rspec")
|
94
|
-
copy_template(".gitignore")
|
95
|
-
copy_template("spec/spec_helper.rb")
|
96
|
-
copy_template("bin/console_irb", "bin/console")
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
private
|
101
|
-
def ensure_file(path_array, content="")
|
102
|
-
filename = File.join(*path_array)
|
103
|
-
FileUtils.mkdir_p(File.dirname(filename))
|
104
|
-
File.write(filename, content)
|
105
|
-
end
|
106
|
-
|
107
|
-
def copy_template(filepath, target_name=nil)
|
108
|
-
from = filepath
|
109
|
-
target_name ||= filepath
|
110
|
-
to = File.join(current_dir, package_relative_path, target_name)
|
111
|
-
FileUtils.mkdir_p(File.dirname(to))
|
112
|
-
# copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
|
113
|
-
FileUtils.copy_entry(from, to, true, false, true)
|
114
|
-
end
|
115
|
-
|
116
|
-
def template_content(file, locals={})
|
117
|
-
template_path = Pathname.new(File.join(File.dirname(__FILE__), "templates")).join(file)
|
118
|
-
template_content = File.read(template_path)
|
119
|
-
ErbalT.render(template_content, locals)
|
120
|
-
end
|
121
|
-
end
|
data/lib/rdm/source_installer.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
class Rdm::SourceInstaller
|
2
|
-
class << self
|
3
|
-
# Install source by locking all it's specs
|
4
|
-
def install(source_path)
|
5
|
-
source_content = File.open(source_path).read
|
6
|
-
source_parser.parse(source_content).package_paths.each do |package_path|
|
7
|
-
full_path = File.join(File.dirname(source_path), package_path, Rdm::PACKAGE_FILENAME)
|
8
|
-
lock(full_path, source_path: source_path, package_path: package_path)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
# Lock package on installation
|
13
|
-
def lock(full_package_path, source_path:, package_path:)
|
14
|
-
package_content = File.open(full_package_path).read
|
15
|
-
|
16
|
-
locked = "source \"#{source_path}\"\r\n\r\n"
|
17
|
-
locked += package_content
|
18
|
-
|
19
|
-
lock_file = "#{full_package_path}.lock"
|
20
|
-
|
21
|
-
return if File.exist?(lock_file) && File.read(lock_file) == locked
|
22
|
-
|
23
|
-
File.open(lock_file, "w+") do |file|
|
24
|
-
file.write(locked)
|
25
|
-
end
|
26
|
-
rescue Errno::ENOENT
|
27
|
-
puts "Can't find package: #{package_path}"
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
def source_parser
|
32
|
-
Rdm::SourceParser
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
Package.rb.lock
|