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/lib/rdm/package_importer.rb
CHANGED
@@ -8,107 +8,117 @@ class Rdm::PackageImporter
|
|
8
8
|
# @param group [Optional<String>] Dependency group
|
9
9
|
# @return [Rdm::Package] Current package
|
10
10
|
def import_file(package_path, group: nil)
|
11
|
-
|
12
|
-
|
13
|
-
package_path = File.join(package_path, Rdm::PACKAGE_LOCK_FILENAME)
|
14
|
-
end
|
15
|
-
package_content = File.open(package_path).read
|
16
|
-
package = package_parser.parse(package_content)
|
17
|
-
|
18
|
-
source = read_and_init_source(package.source)
|
19
|
-
|
20
|
-
# Init Rdm.root based on Rdm.packages directory
|
21
|
-
Rdm.root = File.dirname(package.source)
|
11
|
+
instance.import_file(package_path, group: group)
|
12
|
+
end
|
22
13
|
|
23
|
-
|
24
|
-
|
14
|
+
# Import package and initialize module
|
15
|
+
def import_package(package_name, source:, group: nil)
|
16
|
+
instance.import_package(package_name, source: source, group: group)
|
17
|
+
end
|
25
18
|
|
26
|
-
|
19
|
+
def instance
|
20
|
+
@instance ||= new
|
27
21
|
end
|
28
22
|
|
29
|
-
def
|
30
|
-
|
23
|
+
def reset!
|
24
|
+
@instance = nil
|
31
25
|
end
|
26
|
+
end
|
32
27
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
28
|
+
# Initialize current package using Package.rb
|
29
|
+
# @param package_path [String] Package.rb file path
|
30
|
+
# @param group [Optional<String>] Dependency group
|
31
|
+
# @return [Rdm::Package] Current package
|
32
|
+
def import_file(package_path, group: nil)
|
33
|
+
package = Rdm::PackageParser.parse_file(package_path)
|
34
|
+
source = read_and_init_source(package.source)
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
end
|
36
|
+
# Init Rdm.root based on Rdm.packages directory
|
37
|
+
Rdm.root = File.dirname(package.source)
|
41
38
|
|
42
|
-
|
43
|
-
|
39
|
+
# Import package and it's dependencies
|
40
|
+
import_package(package.name, source: source, group: group.to_s)
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
import_package(dependency, source: source, imported_packages: imported_packages)
|
48
|
-
end
|
42
|
+
package
|
43
|
+
end
|
49
44
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
import_config(dependency, source: source)
|
54
|
-
end
|
55
|
-
imported_configs << dependency
|
56
|
-
end
|
45
|
+
def imported_packages
|
46
|
+
@imported_packages ||= []
|
47
|
+
end
|
57
48
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
49
|
+
def imported_configs
|
50
|
+
@imported_configs ||= []
|
51
|
+
end
|
52
|
+
|
53
|
+
# Import package and initialize module
|
54
|
+
def import_package(package_name, source:, group: nil)
|
55
|
+
return imported_packages if imported_packages.include?(package_name.to_s)
|
56
|
+
package = source.packages[package_name.to_s]
|
57
|
+
|
58
|
+
raise "Can't find package with name: #{package_name}" if package.nil?
|
59
|
+
|
60
|
+
init_package(package, group: group)
|
61
|
+
imported_packages << package_name
|
68
62
|
|
69
|
-
|
63
|
+
# also import local dependencies
|
64
|
+
package.local_dependencies(group).each do |dependency|
|
65
|
+
import_package(dependency, source: source)
|
70
66
|
end
|
71
67
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
68
|
+
# also import config dependencies
|
69
|
+
package.config_dependencies(group).each do |dependency|
|
70
|
+
import_config(dependency, source: source)
|
71
|
+
end
|
76
72
|
|
77
|
-
|
78
|
-
|
73
|
+
# only after importing dependencies - require package itself
|
74
|
+
begin
|
75
|
+
require package_name
|
76
|
+
rescue LoadError => e
|
77
|
+
unless Rdm.settings.silence_missing_package_file
|
78
|
+
package_require_path = "#{package_name}/#{package_subdir_name}/#{package_name}.rb"
|
79
|
+
puts "WARNING: Can't require package #{package_name}, please make sure that file #{package_require_path} exists and it's valid."
|
80
|
+
raise e
|
79
81
|
end
|
82
|
+
end
|
83
|
+
imported_packages
|
84
|
+
end
|
80
85
|
|
81
|
-
|
82
|
-
Rdm.settings.package_subdir_name.to_s
|
83
|
-
end
|
86
|
+
private
|
84
87
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
+
def source_parser
|
89
|
+
Rdm::SourceParser
|
90
|
+
end
|
88
91
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
+
def package_subdir_name
|
93
|
+
Rdm.settings.package_subdir_name.to_s
|
94
|
+
end
|
92
95
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
+
def init_package(package, group:)
|
97
|
+
package_dir_name = File.join(package.path, package_subdir_name)
|
98
|
+
$LOAD_PATH.push(package_dir_name)
|
96
99
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
100
|
+
package.external_dependencies(group).each do |dependency|
|
101
|
+
require dependency
|
102
|
+
end
|
101
103
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
raise "Can't find config with name: #{config_name.to_s}"
|
106
|
-
end
|
107
|
-
Rdm.config.load_config(config, source: source)
|
108
|
-
end
|
104
|
+
package.file_dependencies(group).each do |file_path|
|
105
|
+
require File.join(package.path, file_path)
|
106
|
+
end
|
109
107
|
|
110
|
-
|
111
|
-
|
112
|
-
|
108
|
+
unless ActiveSupport::Dependencies.autoload_paths.include?(package_dir_name)
|
109
|
+
ActiveSupport::Dependencies.autoload_paths << package_dir_name
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def import_config(config_name, source:)
|
114
|
+
return if imported_configs.include?(config_name)
|
115
|
+
config = source.configs[config_name.to_s]
|
116
|
+
raise "Can't find config with name: #{config_name}" if config.nil?
|
117
|
+
Rdm.config.load_config(config, source: source)
|
118
|
+
imported_configs << config_name
|
119
|
+
end
|
120
|
+
|
121
|
+
def read_and_init_source(source_path)
|
122
|
+
source_parser.read_and_init_source(source_path)
|
113
123
|
end
|
114
124
|
end
|
data/lib/rdm/package_parser.rb
CHANGED
@@ -1,7 +1,27 @@
|
|
1
1
|
class Rdm::PackageParser
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
class << self
|
3
|
+
def parse_file(package_path)
|
4
|
+
if File.directory?(package_path)
|
5
|
+
package_path = File.join(package_path, Rdm::PACKAGE_FILENAME)
|
6
|
+
end
|
7
|
+
package_content = File.read(package_path)
|
8
|
+
package = parse(package_content)
|
9
|
+
package.path = File.dirname(package_path)
|
10
|
+
package.source(source_path(package_path))
|
11
|
+
|
12
|
+
package
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def parse(package_content)
|
18
|
+
spec = Rdm::Package.new
|
19
|
+
spec.instance_eval(package_content)
|
20
|
+
spec
|
21
|
+
end
|
22
|
+
|
23
|
+
def source_path(path)
|
24
|
+
Rdm::SourceLocator.locate(path)
|
25
|
+
end
|
6
26
|
end
|
7
|
-
end
|
27
|
+
end
|
data/lib/rdm/settings.rb
CHANGED
@@ -2,15 +2,15 @@ class Rdm::Settings
|
|
2
2
|
SETTING_KEYS = [
|
3
3
|
:role, :package_subdir_name, :configs_dir, :config_path, :role_config_path,
|
4
4
|
:silence_missing_package_file, :silence_missing_package
|
5
|
-
]
|
5
|
+
].freeze
|
6
6
|
|
7
|
-
SETTING_VARIABLES = [:role, :configs_dir, :config_path, :role_config_path]
|
7
|
+
SETTING_VARIABLES = [:role, :configs_dir, :config_path, :role_config_path].freeze
|
8
8
|
|
9
9
|
# Default settings
|
10
10
|
def initialize
|
11
11
|
silence_missing_package(false)
|
12
12
|
silence_missing_package_file(false)
|
13
|
-
package_subdir_name(
|
13
|
+
package_subdir_name('package')
|
14
14
|
configs_dir('configs')
|
15
15
|
end
|
16
16
|
|
@@ -40,24 +40,25 @@ class Rdm::Settings
|
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
43
|
-
def write_setting(key, value)
|
44
|
-
@settings ||= {}
|
45
|
-
@settings[key.to_s] = value
|
46
|
-
end
|
47
43
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
44
|
+
def write_setting(key, value)
|
45
|
+
@settings ||= {}
|
46
|
+
@settings[key.to_s] = value
|
47
|
+
end
|
48
|
+
|
49
|
+
def replace_variables(value, except: nil, additional_vars: {})
|
50
|
+
variables_keys = SETTING_VARIABLES - [except.to_sym]
|
51
|
+
new_value = value
|
52
|
+
additional_vars.each do |key, variable|
|
53
|
+
if new_value.match(":#{key}")
|
54
|
+
new_value = new_value.gsub(":#{key}", variable)
|
55
55
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
end
|
57
|
+
variables_keys.each do |key|
|
58
|
+
if new_value.match(":#{key}")
|
59
|
+
new_value = new_value.gsub(":#{key}", read_setting(key))
|
60
60
|
end
|
61
|
-
new_value
|
62
61
|
end
|
63
|
-
|
62
|
+
new_value
|
63
|
+
end
|
64
|
+
end
|
data/lib/rdm/source.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Rdm
|
2
|
+
class SourceLocator
|
3
|
+
def self.locate(path)
|
4
|
+
Rdm::SourceLocator.new(path).locate
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_accessor :path
|
8
|
+
def initialize(path)
|
9
|
+
@path = path
|
10
|
+
end
|
11
|
+
|
12
|
+
def locate
|
13
|
+
find_source_path_in_hierarchy(path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def find_source_path_in_hierarchy(some_path)
|
17
|
+
some_path = File.expand_path(some_path)
|
18
|
+
raise Rdm::Errors::SourceFileDoesNotExist, path if some_path == '/'
|
19
|
+
return potential_file(some_path) if present?(some_path)
|
20
|
+
find_source_path_in_hierarchy(File.dirname(some_path))
|
21
|
+
end
|
22
|
+
|
23
|
+
def present?(some_path)
|
24
|
+
File.exist?(potential_file(some_path))
|
25
|
+
end
|
26
|
+
|
27
|
+
def potential_file(some_path)
|
28
|
+
File.join(some_path, Rdm::SOURCE_FILENAME)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/rdm/source_parser.rb
CHANGED
@@ -3,83 +3,98 @@ class Rdm::SourceParser
|
|
3
3
|
end
|
4
4
|
|
5
5
|
class << self
|
6
|
-
|
7
|
-
# Read source file, parse and init it's packages and configs
|
8
|
-
# @param source_path [String] Source file path
|
9
|
-
# @return [Rdm::Source] Source
|
10
6
|
def read_and_init_source(source_path)
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
Rdm::SourceParser.new(source_path).read_and_init_source
|
8
|
+
end
|
9
|
+
end
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
11
|
+
attr_accessor :source_path
|
12
|
+
|
13
|
+
def initialize(source_path)
|
14
|
+
@source_path = source_path
|
15
|
+
end
|
16
|
+
|
17
|
+
# Read source file, parse and init it's packages and configs
|
18
|
+
# @param source_path [String] Source file path
|
19
|
+
# @return [Rdm::Source] Source
|
20
|
+
def read_and_init_source
|
21
|
+
source = parse_source_content
|
22
|
+
|
23
|
+
# Setup Rdm
|
24
|
+
if block = source.setup_block
|
25
|
+
Rdm.setup(&block)
|
26
|
+
end
|
27
|
+
validate_rdm_settings!
|
28
|
+
|
29
|
+
init_and_set_packages(source)
|
30
|
+
init_and_set_configs(source)
|
31
|
+
source.init_with(packages: packages, configs: configs)
|
32
|
+
source
|
33
|
+
end
|
34
|
+
|
35
|
+
# Parse source file and return Source object
|
36
|
+
# @return [Rdm::Source] Source
|
37
|
+
def parse_source_content
|
38
|
+
source = Rdm::Source.new(root_path: root_path)
|
39
|
+
source.instance_eval(source_content)
|
40
|
+
source
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
35
44
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
config.name = config_name
|
46
|
-
configs[config_name] = config
|
45
|
+
def init_and_set_packages(source)
|
46
|
+
source.package_paths.each do |package_path|
|
47
|
+
package_full_path = File.join(root_path, package_path)
|
48
|
+
if File.exist?(package_full_path)
|
49
|
+
package_rb_path = File.join(package_full_path, Rdm::PACKAGE_FILENAME)
|
50
|
+
package = Rdm::PackageParser.parse_file(package_rb_path)
|
51
|
+
packages[package.name] = package
|
52
|
+
elsif !settings.silence_missing_package
|
53
|
+
raise "Missing package at folder: #{package_full_path}"
|
47
54
|
end
|
55
|
+
end
|
56
|
+
end
|
48
57
|
|
49
|
-
|
50
|
-
|
58
|
+
def init_and_set_configs(source)
|
59
|
+
source.config_names.each do |config_name|
|
60
|
+
default_path = settings.read_setting(:config_path, vars: { config_name: config_name })
|
61
|
+
role_path = settings.read_setting(:role_config_path, vars: { config_name: config_name })
|
62
|
+
config = Rdm::Config.new
|
63
|
+
config.default_path = default_path
|
64
|
+
config.role_path = role_path
|
65
|
+
config.name = config_name
|
66
|
+
configs[config_name] = config
|
51
67
|
end
|
68
|
+
end
|
52
69
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
70
|
+
# Make sure that all required settings are in place
|
71
|
+
def validate_rdm_settings!
|
72
|
+
if settings.read_setting(:role).nil?
|
73
|
+
raise SourceValidationError, "Please add `role` setting in Rdm.packages. E.g. \r\n setup do\r\n role { ENV['RAILS_ENV'] }\r\n end"
|
74
|
+
end
|
75
|
+
if settings.read_setting(:config_path).nil?
|
76
|
+
raise SourceValidationError, "Please add `config_path` setting in Rdm.packages. E.g. \r\n setup do\r\n config_path :configs_dir/:config_name/default.yml'\r\n end"
|
60
77
|
end
|
78
|
+
end
|
61
79
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
if settings.read_setting(:role).nil?
|
66
|
-
raise SourceValidationError.new(
|
67
|
-
"Please add `role` setting in Rdm.packages. E.g. \r\n setup do\r\n role { ENV['RAILS_ENV'] }\r\n end"
|
68
|
-
)
|
69
|
-
end
|
70
|
-
if settings.read_setting(:config_path).nil?
|
71
|
-
raise SourceValidationError.new(
|
72
|
-
"Please add `config_path` setting in Rdm.packages. E.g. \r\n setup do\r\n config_path :configs_dir/:config_name/default.yml'\r\n end"
|
73
|
-
)
|
74
|
-
end
|
75
|
-
end
|
80
|
+
def root_path
|
81
|
+
File.dirname(source_path)
|
82
|
+
end
|
76
83
|
|
77
|
-
|
78
|
-
|
79
|
-
|
84
|
+
# [String] Source file content
|
85
|
+
def source_content
|
86
|
+
@source_content ||= File.read(source_path)
|
87
|
+
end
|
80
88
|
|
81
|
-
|
82
|
-
|
83
|
-
|
89
|
+
def packages
|
90
|
+
@packages ||= {}
|
91
|
+
end
|
92
|
+
|
93
|
+
def configs
|
94
|
+
@configs ||= {}
|
95
|
+
end
|
96
|
+
|
97
|
+
def settings
|
98
|
+
Rdm.settings
|
84
99
|
end
|
85
|
-
end
|
100
|
+
end
|