rdm 0.4.17 → 0.4.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -8
  3. data/bin/rdm +10 -10
  4. data/example/.rdm/templates/configs/<%=config_path%> +2 -0
  5. data/example/.rdm/templates/configs/<%=role_config_path%> +2 -0
  6. data/example/Rdm.packages +17 -1
  7. data/example/configs/app/default.yml +2 -0
  8. data/example/configs/app/production.yml +2 -0
  9. data/example/configs/database/default.yml +3 -0
  10. data/example/env_files/development.env +3 -0
  11. data/example/env_files/production.env +5 -0
  12. data/example/env_files/test.env +3 -0
  13. data/example/infrastructure/repository/Package.rb +1 -0
  14. data/lib/rdm.rb +7 -14
  15. data/lib/rdm/cli/config.rb +31 -0
  16. data/lib/rdm/config.rb +11 -0
  17. data/lib/rdm/config_locals.rb +11 -0
  18. data/lib/rdm/config_manager.rb +68 -0
  19. data/lib/rdm/config_scope.rb +23 -0
  20. data/lib/rdm/errors.rb +0 -3
  21. data/lib/rdm/gen/config.rb +59 -0
  22. data/lib/rdm/gen/init.rb +4 -0
  23. data/lib/rdm/package.rb +9 -18
  24. data/lib/rdm/package_importer.rb +17 -3
  25. data/lib/rdm/package_parser.rb +0 -1
  26. data/lib/rdm/packages/compiler_service.rb +7 -1
  27. data/lib/rdm/settings.rb +21 -10
  28. data/lib/rdm/source.rb +18 -1
  29. data/lib/rdm/source_parser.rb +45 -2
  30. data/lib/rdm/spec_runner/runner.rb +2 -2
  31. data/lib/rdm/templates/configs/<%=config_path%> +2 -0
  32. data/lib/rdm/templates/configs/<%=role_config_path%> +2 -0
  33. data/lib/rdm/templates/init/Rdm.packages +12 -0
  34. data/lib/rdm/templates/init/env_files/development.env +3 -0
  35. data/lib/rdm/templates/init/env_files/production.env +3 -0
  36. data/lib/rdm/templates/init/env_files/test.env +3 -0
  37. data/lib/rdm/version.rb +1 -1
  38. data/rdm.gemspec +0 -3
  39. data/spec/fixtures/SampleSource.rb +4 -2
  40. data/spec/fixtures/config.yml +2 -0
  41. data/spec/rdm/cli/gen_package_spec.rb +2 -0
  42. data/spec/rdm/config_manager_spec.rb +136 -0
  43. data/spec/rdm/gen/config_spec.rb +31 -0
  44. data/spec/rdm/gen/init_spec.rb +12 -0
  45. data/spec/rdm/gen/package_spec.rb +0 -1
  46. data/spec/rdm/package_importer_spec.rb +2 -34
  47. data/spec/rdm/rdm_spec.rb +1 -1
  48. data/spec/rdm/source_parser_spec.rb +59 -0
  49. data/spec/spec_helper.rb +0 -1
  50. metadata +27 -63
  51. data/example/config/app.yml +0 -6
  52. data/example/infrastructure/repository/fixture.txt +0 -1
  53. data/lib/rdm/utils/ostruct_utils.rb +0 -12
  54. data/lib/rdm/yml_config/config_caster.rb +0 -32
  55. data/lib/rdm/yml_config/config_manager.rb +0 -39
  56. data/lib/rdm/yml_config/config_validator.rb +0 -51
  57. data/lib/rdm/yml_config/env_config.rb +0 -46
  58. data/lib/rdm/yml_config/env_config_dsl.rb +0 -92
  59. data/lib/rdm/yml_config/validate_config.rb +0 -13
  60. data/spec/fixtures/app.yml +0 -17
  61. data/spec/rdm/yml_config/config_caster_spec.rb +0 -64
  62. data/spec/rdm/yml_config/config_manager_spec.rb +0 -7
  63. data/spec/rdm/yml_config/config_validator_spec.rb +0 -190
  64. data/spec/rdm/yml_config/env_config_dsl_spec.rb +0 -123
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f92289ab666f058d12097df562312b6adcb7311433781270958fe4c550a02659
4
- data.tar.gz: 9ebc9af89030643d8368659966bcec6dbc3aee536b065ea204e5d6868bf1ed22
3
+ metadata.gz: 7ef547c24828be0e76ebfead89103580691c5eb09fb7ccae8fbf6e679ceb90c0
4
+ data.tar.gz: d5bce320cb6593f1ecbe6346acc6b109824f4320ef04300ab842f08cbb316aa8
5
5
  SHA512:
6
- metadata.gz: 3bdb3f4ab4ae1eec9732364df1ec3061c4d7f480f34b33af1e5508a8bae4945e602d584243ce6cfb3015ac05063e49da8b6a4dd0ae098f6be96103aba65b31d6
7
- data.tar.gz: 21db2cc6cbb6e57347aa6b06a4a5bb8a8988a4b6b8d4a1c045b84b66513f6d80b2b9e9ccfc9218fe8e6866df702c054f474214379129d7d9974aa0a90f292520
6
+ metadata.gz: d0784e0a54cdd0e0e1a5129460684cea9d5ed3606c997d390902a0393019082ddf163995b6efe44fe929c987d9b3c529377529ccf3e6c049fe10c5e072f499a5
7
+ data.tar.gz: 070261bcff5bb4be884fc6ad9c7ade948598c091dc141c3181e79d9146d09a5204d935929e15c16f4de6a60674506fac673cc433e5fd7d3c43f8e59db7b1b147
@@ -1,12 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rdm (0.4.17)
4
+ rdm (0.4.18)
5
5
  activesupport
6
- attr_validator
7
6
  commander (~> 4.4)
8
- hcast
9
- morf
10
7
 
11
8
  GEM
12
9
  remote: https://rubygems.org/
@@ -17,8 +14,6 @@ GEM
17
14
  minitest (~> 5.1)
18
15
  tzinfo (~> 1.1)
19
16
  ast (2.3.0)
20
- attr_validator (0.2.3)
21
- i18n
22
17
  byebug (9.0.6)
23
18
  codecov (0.2.5)
24
19
  colorize
@@ -30,13 +25,11 @@ GEM
30
25
  concurrent-ruby (1.1.7)
31
26
  diff-lcs (1.3)
32
27
  docile (1.3.2)
33
- hcast (0.3.0)
34
28
  highline (2.0.3)
35
29
  i18n (1.8.5)
36
30
  concurrent-ruby (~> 1.0)
37
31
  json (2.3.1)
38
32
  minitest (5.14.2)
39
- morf (0.0.3)
40
33
  parser (2.3.3.1)
41
34
  ast (~> 2.2)
42
35
  powerpack (0.1.1)
data/bin/rdm CHANGED
@@ -60,7 +60,7 @@ class RdmCliRunner
60
60
  c.action do |args, options|
61
61
  package_name = (args.first || "")
62
62
  defaults = {
63
- current_path: `pwd`.chomp,
63
+ current_path: File.expand_path(`pwd`.chomp),
64
64
  package_name: package_name,
65
65
  path: package_name.downcase.gsub(/\s+/, '_')
66
66
  }
@@ -82,7 +82,7 @@ class RdmCliRunner
82
82
  c.action do |args, options|
83
83
  revision = (args.first || "HEAD")
84
84
  options = {
85
- path: `pwd`.chomp,
85
+ path: File.expand_path(`pwd`.chomp),
86
86
  revision: revision,
87
87
  }
88
88
  Rdm::CLI::DiffPackage.run(options)
@@ -100,7 +100,7 @@ class RdmCliRunner
100
100
  c.action do |args, options|
101
101
  package_name = (args.first || "")
102
102
  opts = {
103
- project_path: `pwd`.chomp,
103
+ project_path: File.expand_path(`pwd`.chomp),
104
104
  package_name: package_name,
105
105
  compile_path: options.path
106
106
  }
@@ -125,7 +125,7 @@ class RdmCliRunner
125
125
 
126
126
  Rdm::CLI::TemplateGenerator.run(
127
127
  template_name: template_name,
128
- current_path: `pwd`.chomp,
128
+ current_path: File.expand_path(`pwd`.chomp),
129
129
  local_path: options_hash.delete(:path),
130
130
  locals: options_hash
131
131
  )
@@ -143,7 +143,7 @@ class RdmCliRunner
143
143
 
144
144
  Rdm::CLI::DependenciesController.run(
145
145
  package_name: package_name,
146
- project_path: `pwd`.chomp
146
+ project_path: File.expand_path(`pwd`.chomp)
147
147
  )
148
148
  end
149
149
  end
@@ -162,7 +162,7 @@ class RdmCliRunner
162
162
 
163
163
  Rdm::CLI::Config.run(
164
164
  config_name: config_name,
165
- current_path: `pwd`.chomp,
165
+ current_path: File.expand_path(`pwd`.chomp),
166
166
  config_data: options_hash
167
167
  )
168
168
  end
@@ -193,11 +193,11 @@ class RdmCliRunner
193
193
  options_hash = options.__hash__
194
194
  options_hash.delete(:trace)
195
195
 
196
- Rdm.root(`pwd`.chomp)
196
+ Rdm.root(File.expand_path(`pwd`.chomp))
197
197
  Rdm::SpecRunner.run(
198
198
  package: package_name,
199
199
  spec_matcher: spec_matcher,
200
- path: `pwd`.chomp,
200
+ path: File.expand_path(`pwd`.chomp),
201
201
  skip_ignored_packages: true,
202
202
  show_missing_packages: true,
203
203
  from: options_hash[:from]
@@ -221,11 +221,11 @@ class RdmCliRunner
221
221
  revision = args[0]
222
222
 
223
223
  ENV['RUBY_ENV'] = 'test'
224
- Rdm.root(`pwd`.chomp)
224
+ Rdm.root(File.expand_path(`pwd`.chomp))
225
225
 
226
226
  Rdm::CLI::DiffSpecRunner.run(
227
227
  revision: revision,
228
- path: `pwd`.chomp
228
+ path: File.expand_path(`pwd`.chomp)
229
229
  )
230
230
  end
231
231
  end
@@ -0,0 +1,2 @@
1
+ <%=config_name%>:
2
+ <%=config_locals%>
@@ -0,0 +1,2 @@
1
+ <%=config_name%>:
2
+ <%=config_locals%>
@@ -3,9 +3,25 @@ setup do
3
3
  ENV['RUBY_ENV'] || "production"
4
4
  end
5
5
 
6
- config_path 'config/app.yml'
6
+ env_file_name do
7
+ ENV['ENV_FILE'] || "production"
8
+ end
9
+
10
+ env_files_dir "env_files"
11
+
12
+ configs_dir "configs"
13
+ config_path ":configs_dir/:config_name/default.yml"
14
+ role_config_path ":configs_dir/:config_name/:role.yml"
15
+
16
+ package_subdir_name "package"
17
+
18
+
19
+ compile_path "/tmp/rdm/:package_name"
7
20
  end
8
21
 
22
+ config :database
23
+ config :app
24
+
9
25
  package "server"
10
26
  package "application/web"
11
27
  package "domain/core"
@@ -0,0 +1,2 @@
1
+ app:
2
+ name: "Sample app"
@@ -0,0 +1,2 @@
1
+ app:
2
+ name: "Sample app (Production)"
@@ -0,0 +1,3 @@
1
+ database:
2
+ username: "root"
3
+ password: "root"
@@ -0,0 +1,3 @@
1
+ RUBY_ENV=development
2
+
3
+ APP_NAME=Application
@@ -0,0 +1,5 @@
1
+ RUBY_ENV=production
2
+
3
+ EXAMPLE_API_KEY=example_key_value
4
+
5
+ APP_NAME=Application
@@ -0,0 +1,3 @@
1
+ RUBY_ENV=test
2
+
3
+ APP_NAME=Application
@@ -5,4 +5,5 @@ end
5
5
 
6
6
  dependency do
7
7
  # require "sequel"
8
+ import_config :app
8
9
  end
data/lib/rdm.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'morf'
2
-
3
1
  module Rdm
4
2
  SOURCE_FILENAME = 'Rdm.packages'.freeze
5
3
  PACKAGE_FILENAME = 'Package.rb'.freeze
@@ -8,7 +6,6 @@ module Rdm
8
6
  require 'rdm/utils/render_util'
9
7
  require 'rdm/utils/string_utils'
10
8
  require 'rdm/utils/file_utils'
11
- require 'rdm/utils/ostruct_utils'
12
9
  require 'rdm/version'
13
10
 
14
11
  # CLI part
@@ -18,9 +15,13 @@ module Rdm
18
15
  require 'rdm/cli/diff_package'
19
16
  require 'rdm/cli/template_generator'
20
17
  require 'rdm/cli/dependencies_controller'
18
+ require 'rdm/cli/config'
21
19
  require 'rdm/cli/diff_spec_runner.rb'
22
20
 
23
21
  # Runtime part
22
+ require 'rdm/config'
23
+ require 'rdm/config_scope'
24
+ require 'rdm/config_manager'
24
25
  require 'rdm/errors'
25
26
  require 'rdm/package'
26
27
  require 'rdm/package_parser'
@@ -32,6 +33,7 @@ module Rdm
32
33
  require 'rdm/git/diff_manager'
33
34
  require 'rdm/git/diff_command'
34
35
  require 'rdm/git/repository_locator'
36
+ require 'rdm/config_locals'
35
37
  require 'rdm/source_modifier'
36
38
 
37
39
  # Package part
@@ -41,6 +43,7 @@ module Rdm
41
43
  # Handlers part
42
44
  require 'rdm/gen/package'
43
45
  require 'rdm/gen/init'
46
+ require 'rdm/gen/config'
44
47
  require 'rdm/handlers/diff_package_handler'
45
48
  require 'rdm/handlers/template_handler'
46
49
  require 'rdm/handlers/dependencies_handler'
@@ -59,13 +62,6 @@ module Rdm
59
62
  require 'rdm/spec_runner/view'
60
63
  require 'rdm/spec_runner/spec_filename_matcher'
61
64
 
62
- require 'rdm/yml_config/env_config_dsl'
63
- require 'rdm/yml_config/validate_config'
64
- require 'rdm/yml_config/env_config'
65
- require 'rdm/yml_config/config_caster'
66
- require 'rdm/yml_config/config_manager'
67
- require 'rdm/yml_config/config_validator'
68
-
69
65
  extend Rdm::Helpers::PathHelper
70
66
 
71
67
  class << self
@@ -74,9 +70,6 @@ module Rdm
74
70
  @stdout = stdout
75
71
 
76
72
  Rdm::PackageImporter.import_file(package_path, group: group)
77
- rescue Rdm::Errors::InvalidConfig => e
78
- puts e.message
79
- exit(0)
80
73
  end
81
74
 
82
75
  # Rdm's internal settings
@@ -86,7 +79,7 @@ module Rdm
86
79
 
87
80
  # Rdm's managed configuration
88
81
  def config
89
- @config ||= Rdm::ConfigManager
82
+ @config ||= Rdm::ConfigManager.new
90
83
  end
91
84
 
92
85
  # Setup Rdm's internal settings
@@ -0,0 +1,31 @@
1
+ class Rdm::CLI::Config
2
+ def self.run(current_path:, config_name:, config_data: {}, stdout: $stdout)
3
+ Rdm::CLI::Config.new(current_path, config_name, config_data, stdout).run
4
+ end
5
+
6
+ def initialize(current_path, config_name, config_data, stdout)
7
+ @current_path = current_path
8
+ @config_name = config_name
9
+ @config_data = config_data
10
+ @stdout = stdout
11
+ end
12
+
13
+ def run
14
+ generated_files = Rdm::Gen::Config.generate(
15
+ current_path: @current_path,
16
+ config_name: @config_name,
17
+ config_data: @config_data
18
+ )
19
+
20
+ puts "Following files were generated:"
21
+ puts generated_files
22
+ rescue Errno::ENOENT => e
23
+ @stdout.puts "Error occurred. Possible reasons:\n #{Rdm::SOURCE_FILENAME} not found. Please run on directory containing #{Rdm::SOURCE_FILENAME} \n#{e.inspect}"
24
+ rescue NoMethodError => e
25
+ @stdout.puts e.message
26
+ rescue Rdm::Errors::SourceFileDoesNotExist => e
27
+ @stdout.puts "Rdm.packages was not found. Run 'rdm init' to create it"
28
+ rescue Rdm::Errors::ConfigExists => e
29
+ @stdout.puts "Config :#{e.message} already exists! Use other name"
30
+ end
31
+ end
@@ -0,0 +1,11 @@
1
+ class Rdm::Config
2
+ attr_accessor :name, :default_path, :role_path
3
+
4
+ def self.build(name:, default_path:, role_path:)
5
+ new.tap do |i|
6
+ i.name = name
7
+ i.default_path = default_path
8
+ i.role_path = role_path
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class Rdm::ConfigLocals
2
+ def initialize(locals = {})
3
+ @locals = locals
4
+ end
5
+
6
+ def to_s
7
+ @locals
8
+ .map {|key, value| "#{key}: #{value}"}
9
+ .join("\n")
10
+ end
11
+ end
@@ -0,0 +1,68 @@
1
+ require 'yaml'
2
+ require 'erb'
3
+
4
+ class Rdm::ConfigManager
5
+ # Update configuration based on given config file
6
+ # @param config [Rdm::Config] Config entity
7
+ # @return root scope [Rdm::ConfigScope] Updated root scope
8
+ def load_config(config, source:)
9
+ if config.default_path
10
+ full_default_path = File.join(source.root_path, config.default_path)
11
+ update_using_file(full_default_path, raise_if_missing: true)
12
+ end
13
+ if config.role_path
14
+ full_role_path = File.join(source.root_path, config.role_path)
15
+ update_using_file(full_role_path, raise_if_missing: false)
16
+ end
17
+ root_scope
18
+ end
19
+
20
+ # Update configuration using given path to config file
21
+ # @param config [Hash<String: AnyValue>] Hash with configuration
22
+ # @return root scope [Rdm::ConfigScope] Updated root scope
23
+ def update_using_file(path, raise_if_missing: true)
24
+ if File.exist?(path)
25
+ compiled_file = ::ERB.new(File.read(path)).result
26
+ hash = YAML.load(compiled_file)
27
+ update_using_hash(hash)
28
+ elsif raise_if_missing
29
+ raise "Config file is not found at path #{path}"
30
+ end
31
+ root_scope
32
+ end
33
+
34
+ # Update configuration based on given hash
35
+ # @param config [Hash<String: AnyValue>] Hash with configuration
36
+ # @return root scope [Rdm::ConfigScope] Updated root scope
37
+ def update_using_hash(hash, scope: nil)
38
+ scope ||= root_scope
39
+
40
+ hash.each do |key, value|
41
+ if value.is_a?(Hash)
42
+ # Try using existing scope
43
+ child_scope = scope.read_attribute(key)
44
+ if !child_scope || !child_scope.is_a?(Rdm::ConfigScope)
45
+ child_scope = Rdm::ConfigScope.new
46
+ end
47
+ update_using_hash(value, scope: child_scope)
48
+ scope.write_attribute(key, child_scope)
49
+ else
50
+ scope.write_attribute(key, value)
51
+ end
52
+ end
53
+ end
54
+
55
+ def method_missing(method_name, *args)
56
+ root_scope.send(method_name, *args)
57
+ end
58
+
59
+ def to_h
60
+ root_scope.to_h
61
+ end
62
+
63
+ private
64
+
65
+ def root_scope
66
+ @root_scope ||= Rdm::ConfigScope.new
67
+ end
68
+ end
@@ -0,0 +1,23 @@
1
+ class Rdm::ConfigScope
2
+ def initialize(attributes = {})
3
+ @attributes = 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
+
18
+ def to_h
19
+ @attributes.each_with_object({}) do |(k, v), h|
20
+ h[k] = Rdm::ConfigScope === v ? v.to_h : v
21
+ end
22
+ end
23
+ end
@@ -56,8 +56,5 @@ module Rdm
56
56
 
57
57
  class ConfigExists < StandardError
58
58
  end
59
-
60
- class InvalidConfig < StandardError
61
- end
62
59
  end
63
60
  end
@@ -0,0 +1,59 @@
1
+ class Rdm::Gen::Config
2
+ TEMPLATE_NAME = 'configs'
3
+
4
+ def self.generate(config_name:, current_path:, config_data: {})
5
+ Rdm::Gen::Config.new(config_name, current_path, config_data = {}).generate
6
+ end
7
+
8
+ def initialize(config_name, current_path, config_data)
9
+ @current_path = current_path
10
+ @config_name = config_name
11
+ @source = get_source
12
+
13
+ @config_locals = Rdm::ConfigLocals.new(config_data)
14
+ end
15
+
16
+ def generate
17
+ @locals = {
18
+ config_name: @config_name,
19
+ config_locals: @config_locals,
20
+ config_path: config_path(@config_name),
21
+ role_config_path: role_config_path(@config_name)
22
+ }
23
+
24
+ generated_files = Rdm::Handlers::TemplateHandler.generate(
25
+ current_path: @current_path,
26
+ locals: @locals,
27
+ template_name: TEMPLATE_NAME,
28
+ local_path: './'
29
+ )
30
+
31
+ Rdm::SourceModifier.add_config(@config_name, get_source.root_path)
32
+
33
+ generated_files
34
+ end
35
+
36
+ private
37
+
38
+ def get_source
39
+ @source ||= Rdm::SourceParser.read_and_init_source(Rdm::SourceLocator.locate(@current_path))
40
+ end
41
+
42
+ def config_path(config_name)
43
+ Rdm.settings.read_setting(
44
+ :config_path,
45
+ vars: {
46
+ config_name: config_name
47
+ }
48
+ )
49
+ end
50
+
51
+ def role_config_path(config_name)
52
+ Rdm.settings.read_setting(
53
+ :role_config_path,
54
+ vars: {
55
+ config_name: config_name
56
+ }
57
+ )
58
+ end
59
+ end