rdm 0.0.5 → 0.0.6
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/example/Rdm.packages +11 -0
- data/example/application/web/Package.rb +0 -2
- data/example/application/web/{lib → package}/web.rb +0 -0
- data/example/application/web/{lib → package}/web/sample_controller.rb +2 -2
- data/example/configs/app/default.yml +1 -0
- data/example/configs/app/production.yml +1 -0
- data/example/configs/database/default.yml +3 -0
- data/example/domain/core/Package.rb +0 -2
- data/example/domain/core/{lib → package}/core.rb +0 -0
- data/example/domain/core/{lib → package}/core/sample_service.rb +2 -2
- data/example/infrastructure/repository/Package.rb +1 -2
- data/example/infrastructure/repository/{lib → package}/repository.rb +0 -0
- data/example/infrastructure/repository/package/repository/sample_repository.rb +6 -0
- data/example/server/package/server.rb +0 -0
- data/example/server/server.rb +1 -2
- data/lib/rdm.rb +20 -0
- data/lib/rdm/config.rb +3 -0
- data/lib/rdm/config_manager.rb +61 -0
- data/lib/rdm/config_scope.rb +17 -0
- data/lib/rdm/package.rb +15 -4
- data/lib/rdm/package_importer.rb +36 -20
- data/lib/rdm/settings.rb +62 -0
- data/lib/rdm/source.rb +48 -0
- data/lib/rdm/source_installer.rb +1 -1
- data/lib/rdm/source_parser.rb +74 -12
- data/lib/rdm/version.rb +1 -1
- data/spec/fixtures/SampleSource.rb +8 -0
- data/spec/rdm/config_manager_spec.rb +66 -0
- data/spec/rdm/package_importer_spec.rb +13 -6
- data/spec/rdm/settings_spec.rb +45 -0
- data/spec/rdm/source_parser_spec.rb +21 -3
- data/spec/spec_helper.rb +4 -0
- metadata +24 -9
- data/example/infrastructure/repository/lib/repository/sample_repository.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a229aa8792154b88ef3f94d0bddb7df1dedd04ad
|
4
|
+
data.tar.gz: e3f92eb13c9e7f06e239b8aeb0781e8cea1e5aa3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7db4647a3b21e7db60bc3728f5f086879319b4a9cfa9cc793f3846484fab6f0e279458b0a791ca284cee49ae9c69f6ace5b3f699a8a718eacb9cf64a2811cfa8
|
7
|
+
data.tar.gz: 4879fbf0609b160ae4e309266e6b2eb953b2b42b1999b293206b4e0c5c5badb89205c52c3067bf7bab514526f7716e4e55c994345c14ea19465aa2f392bb02b4
|
data/example/Rdm.packages
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
setup do
|
2
|
+
role "production"
|
3
|
+
configs_dir "configs"
|
4
|
+
config_path ":configs_dir/:config_name/default.yml"
|
5
|
+
role_config_path ":configs_dir/:config_name/:role.yml"
|
6
|
+
package_subdir_name "package"
|
7
|
+
end
|
8
|
+
|
9
|
+
config :database
|
10
|
+
config :app
|
11
|
+
|
1
12
|
package "server"
|
2
13
|
package "application/web"
|
3
14
|
package "domain/core"
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
app_name: "Sample app"
|
@@ -0,0 +1 @@
|
|
1
|
+
app_name: "Sample app (Production)"
|
File without changes
|
File without changes
|
File without changes
|
data/example/server/server.rb
CHANGED
data/lib/rdm.rb
CHANGED
@@ -3,16 +3,36 @@ module Rdm
|
|
3
3
|
PACKAGE_FILENAME = "Package.rb"
|
4
4
|
PACKAGE_LOCK_FILENAME = "#{PACKAGE_FILENAME}.lock"
|
5
5
|
|
6
|
+
require "rdm/settings"
|
7
|
+
require "rdm/source"
|
6
8
|
require "rdm/source_parser"
|
7
9
|
require "rdm/source_installer"
|
8
10
|
require "rdm/package"
|
9
11
|
require "rdm/package_parser"
|
10
12
|
require "rdm/package_importer"
|
13
|
+
require "rdm/config"
|
14
|
+
require "rdm/config_scope"
|
15
|
+
require "rdm/config_manager"
|
11
16
|
|
12
17
|
class << self
|
13
18
|
# Initialize current package using Package.rb
|
14
19
|
def init(package_path, group = nil)
|
15
20
|
Rdm::PackageImporter.import_file(package_path, group: group)
|
16
21
|
end
|
22
|
+
|
23
|
+
# Rdm's internal settings
|
24
|
+
def settings
|
25
|
+
@settings ||= Rdm::Settings.new
|
26
|
+
end
|
27
|
+
|
28
|
+
# Rdm's managed configuration
|
29
|
+
def config
|
30
|
+
@config ||= Rdm::ConfigManager.new
|
31
|
+
end
|
32
|
+
|
33
|
+
# Setup Rdm's internal settings
|
34
|
+
def setup(&block)
|
35
|
+
settings.instance_eval(&block) if block_given?
|
36
|
+
end
|
17
37
|
end
|
18
38
|
end
|
data/lib/rdm/config.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
class Rdm::ConfigManager
|
3
|
+
|
4
|
+
# Update configuration based on given config file
|
5
|
+
# @param config [Rdm::Config] Config entity
|
6
|
+
# @return root scope [Rdm::ConfigScope] Updated root scope
|
7
|
+
def load_config(config, source:)
|
8
|
+
if config.default_path
|
9
|
+
full_default_path = File.join(source.root_path, config.default_path)
|
10
|
+
update_using_file(full_default_path, raise_if_missing: true)
|
11
|
+
end
|
12
|
+
if config.role_path
|
13
|
+
full_role_path = File.join(source.root_path, config.role_path)
|
14
|
+
update_using_file(full_role_path, raise_if_missing: false)
|
15
|
+
end
|
16
|
+
root_scope
|
17
|
+
end
|
18
|
+
|
19
|
+
# Update configuration using given path to config file
|
20
|
+
# @param config [Hash<String: AnyValue>] Hash with configuration
|
21
|
+
# @return root scope [Rdm::ConfigScope] Updated root scope
|
22
|
+
def update_using_file(path, raise_if_missing: true)
|
23
|
+
if File.exists?(path)
|
24
|
+
hash = YAML.load_file(path)
|
25
|
+
update_using_hash(hash)
|
26
|
+
elsif raise_if_missing
|
27
|
+
raise "Config file is not found at path #{path}"
|
28
|
+
end
|
29
|
+
root_scope
|
30
|
+
end
|
31
|
+
|
32
|
+
# Update configuration based on given hash
|
33
|
+
# @param config [Hash<String: AnyValue>] Hash with configuration
|
34
|
+
# @return root scope [Rdm::ConfigScope] Updated root scope
|
35
|
+
def update_using_hash(hash, scope: nil)
|
36
|
+
scope ||= root_scope
|
37
|
+
|
38
|
+
hash.each do |key, value|
|
39
|
+
if value.is_a?(Hash)
|
40
|
+
# Try using existing scope
|
41
|
+
child_scope = scope.read_attribute(key)
|
42
|
+
if !child_scope || !child_scope.is_a?(Rdm::ConfigScope)
|
43
|
+
child_scope = Rdm::ConfigScope.new
|
44
|
+
end
|
45
|
+
update_using_hash(value, scope: child_scope)
|
46
|
+
scope.write_attribute(key, child_scope)
|
47
|
+
else
|
48
|
+
scope.write_attribute(key, value)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def method_missing(method_name, *args)
|
54
|
+
root_scope.send(method_name, *args)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def root_scope
|
59
|
+
@root_scope ||= Rdm::ConfigScope.new
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Rdm::ConfigScope
|
2
|
+
def initialize(attributes = {})
|
3
|
+
@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
|
+
end
|
data/lib/rdm/package.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class Rdm::Package
|
2
2
|
DEFAULT_GROUP = "_default_"
|
3
3
|
|
4
|
-
attr_accessor :metadata, :local_dependencies, :external_dependencies, :file_dependencies, :path
|
4
|
+
attr_accessor :metadata, :local_dependencies, :external_dependencies, :file_dependencies, :config_dependencies, :path
|
5
5
|
|
6
6
|
def local_dependencies(group = nil)
|
7
7
|
fetch_dependencies(@local_dependencies || {}, group)
|
@@ -15,6 +15,10 @@ class Rdm::Package
|
|
15
15
|
fetch_dependencies(@file_dependencies || {}, group)
|
16
16
|
end
|
17
17
|
|
18
|
+
def config_dependencies(group = nil)
|
19
|
+
fetch_dependencies(@config_dependencies || {}, group)
|
20
|
+
end
|
21
|
+
|
18
22
|
# Import local dependency, e.g another package
|
19
23
|
def import(dependency)
|
20
24
|
@local_dependencies ||= {}
|
@@ -36,6 +40,13 @@ class Rdm::Package
|
|
36
40
|
@file_dependencies[current_group] << file
|
37
41
|
end
|
38
42
|
|
43
|
+
# Import config dependency
|
44
|
+
def import_config(dependency)
|
45
|
+
@config_dependencies ||= {}
|
46
|
+
@config_dependencies[current_group] ||= []
|
47
|
+
@config_dependencies[current_group] << dependency
|
48
|
+
end
|
49
|
+
|
39
50
|
def package
|
40
51
|
yield
|
41
52
|
end
|
@@ -70,11 +81,11 @@ class Rdm::Package
|
|
70
81
|
end
|
71
82
|
|
72
83
|
def exec_metadata(key, value)
|
73
|
-
if value
|
84
|
+
if value.nil?
|
85
|
+
@metadata[key]
|
86
|
+
else
|
74
87
|
@metadata ||= {}
|
75
88
|
@metadata[key] = value
|
76
|
-
else
|
77
|
-
@metadata[key]
|
78
89
|
end
|
79
90
|
end
|
80
91
|
end
|
data/lib/rdm/package_importer.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
class Rdm::PackageImporter
|
2
2
|
class << self
|
3
3
|
# Initialize current package using Package.rb
|
4
|
+
# @param package_path [String] Package.rb file path
|
5
|
+
# @param group [Optional<String>] Dependency group
|
6
|
+
# @return [Rdm::Package] Current package
|
4
7
|
def import_file(package_path, group: nil)
|
5
8
|
if File.directory?(package_path)
|
6
9
|
package_path = File.join(package_path, Rdm::PACKAGE_LOCK_FILENAME)
|
@@ -8,14 +11,16 @@ class Rdm::PackageImporter
|
|
8
11
|
package_content = File.open(package_path).read
|
9
12
|
package = package_parser.parse(package_content)
|
10
13
|
|
11
|
-
|
12
|
-
import_package(package.name,
|
14
|
+
source = read_and_init_source(package.source)
|
15
|
+
import_package(package.name, source: source, group: group.to_s)
|
16
|
+
|
17
|
+
package
|
13
18
|
end
|
14
19
|
|
15
20
|
# Import package and initialize module
|
16
|
-
def import_package(package_name,
|
21
|
+
def import_package(package_name, source:, imported_packages: [], imported_configs: [], group: nil)
|
17
22
|
return if imported_packages.include?(package_name.to_s)
|
18
|
-
package = packages[package_name.to_s]
|
23
|
+
package = source.packages[package_name.to_s]
|
19
24
|
|
20
25
|
if package == nil
|
21
26
|
raise "Can't find package with name: #{package_name.to_s}"
|
@@ -26,14 +31,25 @@ class Rdm::PackageImporter
|
|
26
31
|
|
27
32
|
# also import local dependencies
|
28
33
|
package.local_dependencies(group).each do |dependency|
|
29
|
-
import_package(dependency,
|
34
|
+
import_package(dependency, source: source, imported_packages: imported_packages)
|
35
|
+
end
|
36
|
+
|
37
|
+
# also import config dependencies
|
38
|
+
package.config_dependencies(group).each do |dependency|
|
39
|
+
unless imported_configs.include?(dependency)
|
40
|
+
import_config(dependency, source: source)
|
41
|
+
end
|
42
|
+
imported_configs << dependency
|
30
43
|
end
|
31
44
|
|
32
45
|
# only after importing dependencies - require package itself
|
33
46
|
begin
|
34
47
|
require package_name
|
35
48
|
rescue LoadError
|
36
|
-
|
49
|
+
if Rdm.settings.raises_missing_package_file_exception
|
50
|
+
package_require_path = "#{package_name}/#{package_subdir_name}/#{package_name}.rb"
|
51
|
+
raise "Can't require package #{package_name}, please create file #{package_require_path}"
|
52
|
+
end
|
37
53
|
end
|
38
54
|
|
39
55
|
imported_packages
|
@@ -48,8 +64,12 @@ class Rdm::PackageImporter
|
|
48
64
|
Rdm::PackageParser
|
49
65
|
end
|
50
66
|
|
67
|
+
def package_subdir_name
|
68
|
+
Rdm.settings.package_subdir_name.to_s
|
69
|
+
end
|
70
|
+
|
51
71
|
def init_package(package, group:)
|
52
|
-
$LOAD_PATH.push(File.join(package.path,
|
72
|
+
$LOAD_PATH.push(File.join(package.path, package_subdir_name))
|
53
73
|
|
54
74
|
package.external_dependencies(group).each do |dependency|
|
55
75
|
require dependency
|
@@ -59,20 +79,16 @@ class Rdm::PackageImporter
|
|
59
79
|
end
|
60
80
|
end
|
61
81
|
|
62
|
-
def
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
packages = {}
|
67
|
-
source_parser.parse(source_content).each do |package|
|
68
|
-
package_path = File.join(root_path, package)
|
69
|
-
package_rb_path = File.join(package_path, Rdm::PACKAGE_FILENAME)
|
70
|
-
package_content = File.open(package_rb_path).read
|
71
|
-
package = package_parser.parse(package_content)
|
72
|
-
package.path = package_path
|
73
|
-
packages[package.name] = package
|
82
|
+
def import_config(config_name, source: source)
|
83
|
+
config = source.configs[config_name.to_s]
|
84
|
+
if config == nil
|
85
|
+
raise "Can't find config with name: #{config_name.to_s}"
|
74
86
|
end
|
75
|
-
|
87
|
+
Rdm.config.load_config(config, source: source)
|
88
|
+
end
|
89
|
+
|
90
|
+
def read_and_init_source(source_path)
|
91
|
+
source_parser.read_and_init_source(source_path)
|
76
92
|
end
|
77
93
|
end
|
78
94
|
end
|
data/lib/rdm/settings.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
class Rdm::Settings
|
2
|
+
SETTING_KEYS = [
|
3
|
+
:role, :raises_missing_package_file_exception, :package_subdir_name,
|
4
|
+
:configs_dir, :config_path, :role_config_path
|
5
|
+
]
|
6
|
+
|
7
|
+
SETTING_VARIABLES = [:role, :configs_dir, :config_path, :role_config_path]
|
8
|
+
|
9
|
+
# Default settings
|
10
|
+
def initialize
|
11
|
+
raises_missing_package_file_exception(true)
|
12
|
+
package_subdir_name("package")
|
13
|
+
configs_dir('configs')
|
14
|
+
end
|
15
|
+
|
16
|
+
SETTING_KEYS.each do |key|
|
17
|
+
define_method(key) do |value = nil|
|
18
|
+
fetch_setting key, value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def fetch_setting(key, value = nil)
|
23
|
+
if value.nil?
|
24
|
+
read_setting(key)
|
25
|
+
else
|
26
|
+
write_setting(key, value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def read_setting(key, vars: {})
|
31
|
+
value = @settings[key.to_s]
|
32
|
+
if value.is_a?(Proc)
|
33
|
+
value.call
|
34
|
+
elsif value.is_a?(String)
|
35
|
+
replace_variables(value, except: key, additional_vars: vars)
|
36
|
+
else
|
37
|
+
value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def write_setting(key, value)
|
43
|
+
@settings ||= {}
|
44
|
+
@settings[key.to_s] = value
|
45
|
+
end
|
46
|
+
|
47
|
+
def replace_variables(value, except: nil, additional_vars: {})
|
48
|
+
variables_keys = SETTING_VARIABLES - [except.to_sym]
|
49
|
+
new_value = value
|
50
|
+
additional_vars.each do |key, variable|
|
51
|
+
if new_value.match(":#{key.to_s}")
|
52
|
+
new_value = new_value.gsub(":#{key.to_s}", variable)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
variables_keys.each do |key|
|
56
|
+
if new_value.match(":#{key}")
|
57
|
+
new_value = new_value.gsub(":#{key}", read_setting(key))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
new_value
|
61
|
+
end
|
62
|
+
end
|
data/lib/rdm/source.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
class Rdm::Source
|
2
|
+
attr_reader :setup_block, :config_names, :package_paths, :root_path
|
3
|
+
|
4
|
+
def initialize(root_path:)
|
5
|
+
@root_path = root_path
|
6
|
+
end
|
7
|
+
|
8
|
+
# Set setup block for source
|
9
|
+
# @param block [Proc] Setup block
|
10
|
+
def setup(&block)
|
11
|
+
@setup_block = block
|
12
|
+
end
|
13
|
+
|
14
|
+
# Add config to list of known configs
|
15
|
+
# @param config_name [String] Config name
|
16
|
+
def config(config_name)
|
17
|
+
@config_names ||= []
|
18
|
+
@config_names << config_name.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
# Add package to list of known packages
|
22
|
+
# @param package_path [String] Package path
|
23
|
+
def package(package_path)
|
24
|
+
@package_paths ||= []
|
25
|
+
@package_paths << package_path
|
26
|
+
end
|
27
|
+
|
28
|
+
# Init source by adding read packages and configs
|
29
|
+
# @param value [Hash<String: Rdm::Package>] Hash of packages by it's name
|
30
|
+
# @param value [Hash<String: Rdm::Config>] Hash of configs by it's name
|
31
|
+
# @return [Hash<String: Rdm::Package>] Hash of packages by it's name
|
32
|
+
def init_with(packages:, configs:)
|
33
|
+
@packages = packages
|
34
|
+
@configs = configs
|
35
|
+
end
|
36
|
+
|
37
|
+
# Read initialized packages
|
38
|
+
# @return [Hash<String: Rdm::Package>] Hash of packages by it's name
|
39
|
+
def packages
|
40
|
+
@packages || {}
|
41
|
+
end
|
42
|
+
|
43
|
+
# Read initialized configs
|
44
|
+
# @return [Hash<String: Rdm::Config>] Hash of configs by it's name
|
45
|
+
def configs
|
46
|
+
@configs || {}
|
47
|
+
end
|
48
|
+
end
|
data/lib/rdm/source_installer.rb
CHANGED
@@ -3,7 +3,7 @@ class Rdm::SourceInstaller
|
|
3
3
|
# Install source by locking all it's specs
|
4
4
|
def install(source_path)
|
5
5
|
source_content = File.open(source_path).read
|
6
|
-
source_parser.parse(source_content).each do |package_path|
|
6
|
+
source_parser.parse(source_content).package_paths.each do |package_path|
|
7
7
|
full_path = File.join(File.dirname(source_path), package_path, Rdm::PACKAGE_FILENAME)
|
8
8
|
lock(full_path, source_path: source_path, package_path: package_path)
|
9
9
|
end
|
data/lib/rdm/source_parser.rb
CHANGED
@@ -1,19 +1,81 @@
|
|
1
1
|
class Rdm::SourceParser
|
2
|
-
class
|
3
|
-
attr_accessor :package_paths
|
4
|
-
|
5
|
-
def package(package_path)
|
6
|
-
self.package_paths ||= []
|
7
|
-
self.package_paths << package_path
|
8
|
-
end
|
2
|
+
class SourceValidationError < StandardError
|
9
3
|
end
|
10
4
|
|
11
5
|
class << self
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
+
def read_and_init_source(source_path)
|
11
|
+
root_path = File.dirname(source_path)
|
12
|
+
source_content = File.open(source_path).read
|
13
|
+
source = parse(source_content, root_path: root_path)
|
14
|
+
|
15
|
+
# Setup Rdm
|
16
|
+
if block = source.setup_block
|
17
|
+
Rdm.setup(&block)
|
18
|
+
end
|
19
|
+
validate_rdm_settings!
|
20
|
+
|
21
|
+
# Init and set packages
|
22
|
+
packages = {}
|
23
|
+
source.package_paths.each do |package_path|
|
24
|
+
package_full_path = File.join(root_path, package_path)
|
25
|
+
package_rb_path = File.join(package_full_path, Rdm::PACKAGE_FILENAME)
|
26
|
+
package_content = File.open(package_rb_path).read
|
27
|
+
package = package_parser.parse(package_content)
|
28
|
+
package.path = package_full_path
|
29
|
+
packages[package.name] = package
|
30
|
+
end
|
31
|
+
|
32
|
+
# Init and set configs
|
33
|
+
configs = {}
|
34
|
+
source.config_names.each do |config_name|
|
35
|
+
default_path = settings.read_setting(:config_path, vars: {config_name: config_name})
|
36
|
+
role_path = settings.read_setting(:role_config_path, vars: {config_name: config_name})
|
37
|
+
|
38
|
+
config = Rdm::Config.new
|
39
|
+
config.default_path = default_path
|
40
|
+
config.role_path = role_path
|
41
|
+
config.name = config_name
|
42
|
+
configs[config_name] = config
|
43
|
+
end
|
44
|
+
|
45
|
+
source.init_with(packages: packages, configs: configs)
|
46
|
+
source
|
47
|
+
end
|
48
|
+
|
49
|
+
# Parse source file and return Source object
|
50
|
+
# @param source_content [String] Source file content
|
51
|
+
# @return [Rdm::Source] Source
|
52
|
+
def parse(source_content, root_path: nil)
|
53
|
+
source = Rdm::Source.new(root_path: root_path)
|
54
|
+
source.instance_eval(source_content)
|
55
|
+
source
|
17
56
|
end
|
57
|
+
|
58
|
+
private
|
59
|
+
# Make sure that all required settings are in place
|
60
|
+
def validate_rdm_settings!
|
61
|
+
if Rdm.settings.read_setting(:role).nil?
|
62
|
+
raise SourceValidationError.new(
|
63
|
+
"Please set `role` value in Rdm.packages. E.g. \r\n setup do\r\n role { ENV['RAILS_ENV'] }\r\n end"
|
64
|
+
)
|
65
|
+
end
|
66
|
+
if Rdm.settings.read_setting(:config_path).nil?
|
67
|
+
raise SourceValidationError.new(
|
68
|
+
"Please set `config_path` value in Rdm.packages. E.g. \r\n setup do\r\n config_path :configs_dir/:config_name/default.yml'\r\n end"
|
69
|
+
)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def settings
|
74
|
+
Rdm.settings
|
75
|
+
end
|
76
|
+
|
77
|
+
def package_parser
|
78
|
+
Rdm::PackageParser
|
79
|
+
end
|
18
80
|
end
|
19
81
|
end
|
data/lib/rdm/version.rb
CHANGED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rdm::ConfigManager do
|
4
|
+
subject { Rdm::ConfigManager.new }
|
5
|
+
|
6
|
+
describe "#update_using_hash" do
|
7
|
+
before :each do
|
8
|
+
subject.update_using_hash(
|
9
|
+
database: {
|
10
|
+
username: "foo",
|
11
|
+
password: "bar"
|
12
|
+
},
|
13
|
+
lib_name: "rdm",
|
14
|
+
version: 1,
|
15
|
+
published: true,
|
16
|
+
draft: false,
|
17
|
+
features: ["dependency_manager", "config_manager"]
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns given value for string" do
|
22
|
+
expect(subject.lib_name).to eq("rdm")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns given value for int" do
|
26
|
+
expect(subject.version).to eq(1)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns given value for true bool" do
|
30
|
+
expect(subject.published).to eq(true)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns given value for false bool" do
|
34
|
+
expect(subject.draft).to eq(false)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns given value for array" do
|
38
|
+
expect(subject.features).to eq(["dependency_manager", "config_manager"])
|
39
|
+
end
|
40
|
+
|
41
|
+
it "creates another child scope for nested hash" do
|
42
|
+
expect(subject.database).to be_instance_of(Rdm::ConfigScope)
|
43
|
+
expect(subject.database.username).to eq("foo")
|
44
|
+
expect(subject.database.password).to eq("bar")
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when already has config" do
|
48
|
+
before :each do
|
49
|
+
subject.update_using_hash(
|
50
|
+
database: {
|
51
|
+
username: "new_username",
|
52
|
+
password: "new_password"
|
53
|
+
}
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "keeps old configs" do
|
58
|
+
expect(subject.lib_name).to eq('rdm')
|
59
|
+
end
|
60
|
+
|
61
|
+
it "rewrites new configs" do
|
62
|
+
expect(subject.database.username).to eq('new_username')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -4,12 +4,19 @@ describe Rdm::PackageImporter do
|
|
4
4
|
def build_package(name, dependencies: [])
|
5
5
|
package = Rdm::Package.new
|
6
6
|
package.name(name)
|
7
|
+
package.path = name
|
7
8
|
dependencies.each do |dependency|
|
8
9
|
package.import(dependency)
|
9
10
|
end
|
10
11
|
package
|
11
12
|
end
|
12
13
|
|
14
|
+
def build_source(packages:)
|
15
|
+
source = Rdm::Source.new(root_path: nil)
|
16
|
+
source.init_with(packages: packages, configs: {})
|
17
|
+
source
|
18
|
+
end
|
19
|
+
|
13
20
|
describe "#import_package" do
|
14
21
|
subject { Rdm::PackageImporter }
|
15
22
|
|
@@ -17,9 +24,9 @@ describe Rdm::PackageImporter do
|
|
17
24
|
it "imports all depended global packages" do
|
18
25
|
web_pack = build_package("web", dependencies: ["core"])
|
19
26
|
core_pack = build_package("core")
|
20
|
-
|
27
|
+
source = build_source(packages: {"web" => web_pack, "core" => core_pack})
|
21
28
|
|
22
|
-
imported = subject.import_package("web",
|
29
|
+
imported = subject.import_package("web", source: source)
|
23
30
|
expect(imported).to include("core")
|
24
31
|
end
|
25
32
|
end
|
@@ -33,9 +40,9 @@ describe Rdm::PackageImporter do
|
|
33
40
|
core_pack = build_package("core")
|
34
41
|
factory_pack = build_package("factory")
|
35
42
|
|
36
|
-
|
43
|
+
source = build_source(packages: {"web" => web_pack, "core" => core_pack, "factory" => factory_pack})
|
37
44
|
|
38
|
-
imported = subject.import_package("web",
|
45
|
+
imported = subject.import_package("web", source: source, group: "test")
|
39
46
|
expect(imported).to include("factory")
|
40
47
|
end
|
41
48
|
|
@@ -47,9 +54,9 @@ describe Rdm::PackageImporter do
|
|
47
54
|
core_pack = build_package("core")
|
48
55
|
factory_pack = build_package("factory")
|
49
56
|
|
50
|
-
|
57
|
+
source = build_source(packages: {"web" => web_pack, "core" => core_pack, "factory" => factory_pack})
|
51
58
|
|
52
|
-
imported = subject.import_package("web",
|
59
|
+
imported = subject.import_package("web", source: source)
|
53
60
|
expect(imported).to_not include("factory")
|
54
61
|
end
|
55
62
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rdm::Settings do
|
4
|
+
subject { Rdm::Settings.new }
|
5
|
+
|
6
|
+
describe "#fetch_setting" do
|
7
|
+
it "writes setting if value provided" do
|
8
|
+
expect(subject.send(:read_setting, :test)).to be_nil
|
9
|
+
subject.fetch_setting(:test, "test value")
|
10
|
+
expect(subject.send(:read_setting, :test)).to eq("test value")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "reads setting if no value provided" do
|
14
|
+
subject.send(:write_setting, :test, "test value")
|
15
|
+
expect(subject.fetch_setting(:test)).to eq("test value")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#read_setting" do
|
20
|
+
it "returns setting if it's boolean" do
|
21
|
+
subject.send(:write_setting, :bool_value, true)
|
22
|
+
expect(subject.read_setting(:bool_value)).to eq(true)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns result of proc if it's a proc" do
|
26
|
+
proc_value = proc {
|
27
|
+
"proc value"
|
28
|
+
}
|
29
|
+
subject.send(:write_setting, :proc_value, proc_value)
|
30
|
+
expect(subject.read_setting(:proc_value)).to eq("proc value")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "replaces variables if it's a string" do
|
34
|
+
subject.role("test")
|
35
|
+
subject.fetch_setting("some-path", "/path/:role.yml")
|
36
|
+
expect(subject.read_setting("some-path")).to eq("/path/test.yml")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "replaces additional variables if it's a string" do
|
40
|
+
subject.role("foo")
|
41
|
+
subject.fetch_setting("some-path", "/path/:role/:myvar.yml")
|
42
|
+
expect(subject.read_setting("some-path", vars: {myvar: "bar"})).to eq("/path/foo/bar.yml")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -4,15 +4,33 @@ describe Rdm::SourceParser do
|
|
4
4
|
describe "#parse" do
|
5
5
|
subject { Rdm::SourceParser }
|
6
6
|
|
7
|
+
let(:fixtures_path) {
|
8
|
+
File.join(File.expand_path("../../", __FILE__), 'fixtures')
|
9
|
+
}
|
10
|
+
|
7
11
|
let(:source_content) {
|
8
|
-
|
12
|
+
File.read(File.join(fixtures_path, "SampleSource.rb"))
|
9
13
|
}
|
10
14
|
|
11
|
-
|
12
|
-
|
15
|
+
before :each do
|
16
|
+
@source = subject.parse(source_content)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns Source object" do
|
20
|
+
expect(@source.is_a?(Rdm::Source)).to be_truthy
|
21
|
+
end
|
22
|
+
|
23
|
+
it "parses all packages paths" do
|
24
|
+
paths = @source.package_paths
|
13
25
|
expect(paths.count).to be(2)
|
14
26
|
expect(paths).to include("application/web")
|
15
27
|
expect(paths).to include("domain/core")
|
16
28
|
end
|
29
|
+
|
30
|
+
it "parses all config names" do
|
31
|
+
names = @source.config_names
|
32
|
+
expect(names.count).to be(1)
|
33
|
+
expect(names).to include("database")
|
34
|
+
end
|
17
35
|
end
|
18
36
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Droid Labs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,26 +83,38 @@ files:
|
|
83
83
|
- example/Rdm.packages
|
84
84
|
- example/Readme.md
|
85
85
|
- example/application/web/Package.rb
|
86
|
-
- example/application/web/
|
87
|
-
- example/application/web/
|
86
|
+
- example/application/web/package/web.rb
|
87
|
+
- example/application/web/package/web/sample_controller.rb
|
88
|
+
- example/configs/app/default.yml
|
89
|
+
- example/configs/app/production.yml
|
90
|
+
- example/configs/database/default.yml
|
88
91
|
- example/domain/core/Package.rb
|
89
|
-
- example/domain/core/
|
90
|
-
- example/domain/core/
|
92
|
+
- example/domain/core/package/core.rb
|
93
|
+
- example/domain/core/package/core/sample_service.rb
|
91
94
|
- example/infrastructure/repository/Package.rb
|
92
|
-
- example/infrastructure/repository/
|
93
|
-
- example/infrastructure/repository/
|
95
|
+
- example/infrastructure/repository/package/repository.rb
|
96
|
+
- example/infrastructure/repository/package/repository/sample_repository.rb
|
94
97
|
- example/server/Package.rb
|
98
|
+
- example/server/package/server.rb
|
95
99
|
- example/server/server.rb
|
96
100
|
- lib/rdm.rb
|
101
|
+
- lib/rdm/config.rb
|
102
|
+
- lib/rdm/config_manager.rb
|
103
|
+
- lib/rdm/config_scope.rb
|
97
104
|
- lib/rdm/package.rb
|
98
105
|
- lib/rdm/package_importer.rb
|
99
106
|
- lib/rdm/package_parser.rb
|
107
|
+
- lib/rdm/settings.rb
|
108
|
+
- lib/rdm/source.rb
|
100
109
|
- lib/rdm/source_installer.rb
|
101
110
|
- lib/rdm/source_parser.rb
|
102
111
|
- lib/rdm/version.rb
|
103
112
|
- rdm.gemspec
|
113
|
+
- spec/fixtures/SampleSource.rb
|
114
|
+
- spec/rdm/config_manager_spec.rb
|
104
115
|
- spec/rdm/package_importer_spec.rb
|
105
116
|
- spec/rdm/package_parser_spec.rb
|
117
|
+
- spec/rdm/settings_spec.rb
|
106
118
|
- spec/rdm/source_parser_spec.rb
|
107
119
|
- spec/spec_helper.rb
|
108
120
|
homepage:
|
@@ -124,12 +136,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
136
|
version: '0'
|
125
137
|
requirements: []
|
126
138
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.4.3
|
128
140
|
signing_key:
|
129
141
|
specification_version: 4
|
130
142
|
summary: Ruby Dependency Manager
|
131
143
|
test_files:
|
144
|
+
- spec/fixtures/SampleSource.rb
|
145
|
+
- spec/rdm/config_manager_spec.rb
|
132
146
|
- spec/rdm/package_importer_spec.rb
|
133
147
|
- spec/rdm/package_parser_spec.rb
|
148
|
+
- spec/rdm/settings_spec.rb
|
134
149
|
- spec/rdm/source_parser_spec.rb
|
135
150
|
- spec/spec_helper.rb
|