rdm 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/Gemfile.lock +80 -0
  4. data/bin/rdm +78 -10
  5. data/example/.rdm/helpers/render_helper.rb +12 -0
  6. data/example/.rdm/templates/package/.gitignore +1 -0
  7. data/example/.rdm/templates/package/.rspec +2 -0
  8. data/example/.rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>.rb +3 -0
  9. data/example/.rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>/.gitkeep +0 -0
  10. data/{lib/rdm/templates/package/package.rb.erb → example/.rdm/templates/package/Package.rb} +0 -0
  11. data/{lib/rdm/templates/package/bin/console_irb → example/.rdm/templates/package/bin/console} +0 -0
  12. data/example/.rdm/templates/package/spec/spec_helper.rb +10 -0
  13. data/example/.rdm/templates/repository/dao/<%=name%>_dao.rb +4 -0
  14. data/example/.rdm/templates/repository/mapper/<%=name%>_mapper.rb +2 -0
  15. data/example/.rdm/templates/repository/repository/<%=name%>_repository.rb +2 -0
  16. data/example/.rdm/templates/repository/views/users.html.erb +2 -0
  17. data/example/Gemfile.lock +50 -0
  18. data/example/Rdm.packages +1 -0
  19. data/example/tests/diff_run +0 -0
  20. data/example/tests/run +0 -0
  21. data/lib/rdm.rb +40 -8
  22. data/lib/rdm/cli/compile_package.rb +56 -0
  23. data/lib/rdm/cli/dependencies_controller.rb +30 -0
  24. data/lib/rdm/cli/diff_package.rb +21 -0
  25. data/lib/rdm/cli/gen_package.rb +24 -32
  26. data/lib/rdm/cli/init.rb +20 -27
  27. data/lib/rdm/cli/template_generator.rb +38 -0
  28. data/lib/rdm/errors.rb +37 -0
  29. data/lib/rdm/gen/init.rb +29 -44
  30. data/lib/rdm/gen/package.rb +24 -78
  31. data/lib/rdm/git/diff_command.rb +13 -0
  32. data/lib/rdm/git/diff_manager.rb +30 -0
  33. data/lib/rdm/git/repository_locator.rb +23 -0
  34. data/lib/rdm/handlers/dependencies_handler.rb +110 -0
  35. data/lib/rdm/handlers/diff_package_handler.rb +48 -0
  36. data/lib/rdm/handlers/template_handler.rb +118 -0
  37. data/lib/rdm/helpers/path_helper.rb +15 -0
  38. data/lib/rdm/package.rb +6 -0
  39. data/lib/rdm/package_importer.rb +1 -1
  40. data/lib/rdm/packages/compiler_service.rb +78 -0
  41. data/lib/rdm/packages/locator.rb +28 -0
  42. data/lib/rdm/settings.rb +14 -1
  43. data/lib/rdm/spec_runner.rb +5 -0
  44. data/lib/rdm/spec_runner/command_generator.rb +28 -0
  45. data/lib/rdm/spec_runner/command_params.rb +3 -0
  46. data/lib/rdm/spec_runner/package_fetcher.rb +13 -0
  47. data/lib/rdm/spec_runner/runner.rb +122 -0
  48. data/lib/rdm/spec_runner/view.rb +20 -0
  49. data/lib/rdm/templates/init/.rdm/helpers/render_helper.rb +12 -0
  50. data/lib/rdm/templates/init/{Gemfile.erb → Gemfile} +0 -0
  51. data/lib/rdm/templates/init/{Rdm.packages.erb → Rdm.packages} +0 -0
  52. data/lib/rdm/templates/init/{Readme.md.erb → Readme.md} +0 -0
  53. data/lib/rdm/templates/init/tests/diff_run +29 -0
  54. data/lib/rdm/templates/init/tests/run +7 -210
  55. data/lib/rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>.rb +3 -0
  56. data/lib/rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>/.gitkeep +0 -0
  57. data/lib/rdm/templates/package/Package.rb +8 -0
  58. data/lib/rdm/templates/package/bin/console +16 -0
  59. data/lib/rdm/templates/template_detector.rb +32 -0
  60. data/lib/rdm/templates/template_renderer.rb +49 -0
  61. data/lib/rdm/utils/file_utils.rb +20 -0
  62. data/lib/rdm/utils/render_util.rb +24 -0
  63. data/lib/rdm/utils/string_utils.rb +16 -0
  64. data/lib/rdm/version.rb +1 -1
  65. data/rdm.gemspec +1 -1
  66. data/spec/helpers/example_project_helper.rb +217 -0
  67. data/spec/helpers/git_commands_helper.rb +13 -0
  68. data/spec/rdm/cli/compile_package_spec.rb +114 -0
  69. data/spec/rdm/cli/dependencies_controller_spec.rb +50 -0
  70. data/spec/rdm/cli/diff_package_spec.rb +5 -0
  71. data/spec/rdm/cli/gen_package_spec.rb +60 -86
  72. data/spec/rdm/cli/init_spec.rb +53 -70
  73. data/spec/rdm/gen/init_spec.rb +21 -38
  74. data/spec/rdm/gen/package_spec.rb +70 -51
  75. data/spec/rdm/git/diff_manager_spec.rb +81 -0
  76. data/spec/rdm/git/repository_locator_spec.rb +31 -0
  77. data/spec/rdm/handlers/dependencies_handler_spec.rb +84 -0
  78. data/spec/rdm/handlers/diff_package_handler_spec.rb +78 -0
  79. data/spec/rdm/handlers/template_handler_spec.rb +94 -0
  80. data/spec/rdm/helpers/path_helper_spec.rb +52 -0
  81. data/spec/rdm/package/compiler_service_spec.rb +124 -0
  82. data/spec/rdm/package/locator_spec.rb +31 -0
  83. data/spec/rdm/rdm_spec.rb +2 -2
  84. data/spec/rdm/spec_runner/runner_spec.rb +12 -0
  85. data/spec/rdm/templates/template_detector_spec.rb +39 -0
  86. data/spec/rdm/templates/template_renderer_spec.rb +42 -0
  87. data/spec/spec_helper.rb +31 -25
  88. metadata +84 -17
  89. data/lib/rdm/gen/concerns/template_handling.rb +0 -81
  90. data/lib/rdm/support/colorize.rb +0 -106
  91. data/lib/rdm/support/render.rb +0 -17
  92. data/lib/rdm/support/template.rb +0 -30
  93. data/lib/rdm/templates/package/main_module_file.rb.erb +0 -3
  94. data/spec/rdm/support/colorize_spec.rb +0 -24
  95. data/spec/rdm/support/template_spec.rb +0 -20
@@ -0,0 +1,28 @@
1
+ class Rdm::Packages::Locator
2
+ class << self
3
+ def locate(path)
4
+ raise Rdm::Errors::PackageFileDoesNotFound, path if source_present?(path)
5
+ raise Rdm::Errors::SourceFileDoesNotExist, path if root_reached?(path)
6
+
7
+ return path if package_present?(path)
8
+
9
+ locate(File.dirname(path))
10
+ end
11
+
12
+ def root_reached?(path)
13
+ File.expand_path(path) == '/'
14
+ end
15
+
16
+ def source_present?(path)
17
+ expected_source_file = File.join(path, Rdm::SOURCE_FILENAME)
18
+
19
+ File.exist?(expected_source_file)
20
+ end
21
+
22
+ def package_present?(path)
23
+ expected_package_file = File.join(path, Rdm::PACKAGE_FILENAME)
24
+
25
+ File.exist?(expected_package_file)
26
+ end
27
+ end
28
+ end
@@ -1,7 +1,8 @@
1
1
  class Rdm::Settings
2
2
  SETTING_KEYS = [
3
3
  :role, :package_subdir_name, :configs_dir, :config_path, :role_config_path,
4
- :silence_missing_package_file, :silence_missing_package
4
+ :silence_missing_package_file, :silence_missing_package, :compile_path,
5
+ :compile_ignore_files, :compile_add_files
5
6
  ].freeze
6
7
 
7
8
  SETTING_VARIABLES = [:role, :configs_dir, :config_path, :role_config_path].freeze
@@ -12,6 +13,18 @@ class Rdm::Settings
12
13
  silence_missing_package_file(false)
13
14
  package_subdir_name('package')
14
15
  configs_dir('configs')
16
+ compile_ignore_files([
17
+ '.gitignore',
18
+ '.byebug_history',
19
+ '.irbrc',
20
+ '.rspec',
21
+ '*_spec.rb',
22
+ '*.log'
23
+ ])
24
+ compile_add_files([
25
+ 'Gemfile',
26
+ 'Gemfile.lock'
27
+ ])
15
28
  end
16
29
 
17
30
  SETTING_KEYS.each do |key|
@@ -0,0 +1,5 @@
1
+ module Rdm::SpecRunner
2
+ def self.run(path: nil, package: nil, spec_mather: nil)
3
+ Rdm::SpecRunner::Runner.new(path: path, package: package, spec_mather: spec_matcher).run
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ class Rdm::SpecRunner::CommandGenerator
2
+ attr_accessor :package_name, :package_path, :spec_matcher
3
+ def initialize(package_name:, package_path:, spec_matcher:)
4
+ @package_name = package_name
5
+ @package_path = package_path
6
+ @spec_matcher = spec_matcher
7
+ end
8
+
9
+ def spec_count
10
+ Dir[File.join(package_path, 'spec/**/*_spec.rb')].size
11
+ end
12
+
13
+ def command
14
+ "print_message(
15
+ '**** Package: #{package_name} *****') \\
16
+ && system('cd #{package_path} \\
17
+ && bundle exec rspec --color --tty #{spec_matcher}', out: $stdout, err: :out)"
18
+ end
19
+
20
+ def generate
21
+ Rdm::SpecRunner::CommandParams.new.tap do |cp|
22
+ cp.package_name = package_name
23
+ cp.package_path = package_path
24
+ cp.command = command
25
+ cp.spec_count = spec_count
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ class Rdm::SpecRunner::CommandParams
2
+ attr_accessor :package_name, :package_path, :spec_matcher, :spec_count, :command
3
+ end
@@ -0,0 +1,13 @@
1
+ class Rdm::SpecRunner::PackageFetcher
2
+ def initialize(path)
3
+ @app_path = path
4
+ end
5
+
6
+ def packages
7
+ Rdm::SourceParser.read_and_init_source(rdm_packages_path).packages
8
+ end
9
+
10
+ def rdm_packages_path
11
+ Rdm::SourceLocator.locate(@app_path)
12
+ end
13
+ end
@@ -0,0 +1,122 @@
1
+ class Rdm::SpecRunner::Runner
2
+ attr_accessor :skipped_packages
3
+ attr_accessor :prepared_command_params
4
+ attr_accessor :command
5
+ def initialize(package: nil, spec_matcher: nil, path: nil)
6
+ @package = package,
7
+ @spec_matcher = spec_matcher.to_s
8
+ @skipped_packages = []
9
+ @path = path
10
+ @run_all = @package.nil?
11
+ end
12
+
13
+ def run
14
+ prepare!
15
+ check_input_params!
16
+ display_missing_specs
17
+ execute_command
18
+ end
19
+
20
+ def packages
21
+ @packages ||= Rdm::SpecRunner::PackageFetcher.new(@path).packages
22
+ end
23
+
24
+ def view
25
+ @view ||= Rdm::SpecRunner::View.new
26
+ end
27
+
28
+ def print_message(msg)
29
+ puts msg
30
+ true
31
+ end
32
+
33
+ def exit_with_message(msg)
34
+ print_message(msg)
35
+ exit 1
36
+ end
37
+
38
+ def check_input_params!
39
+ if @package_name
40
+ unless is_package_included?(@package_name)
41
+ exit_with_message(
42
+ view.package_not_found_message(@package_name, prepared_command_params)
43
+ )
44
+ end
45
+
46
+ if skipped_packages.include?(@package_name)
47
+ exit_with_message(
48
+ view.no_specs_for_package(@package_name)
49
+ )
50
+ end
51
+ end
52
+ end
53
+
54
+ def is_package_included?(package_name)
55
+ !prepared_command_params.select do |x|
56
+ x.package_name == package_name
57
+ end.empty?
58
+ end
59
+
60
+ def prepare!
61
+ prepared_command_params = []
62
+ skipped_packages = []
63
+ command = nil
64
+ prepare_command_params
65
+ prepare_skipped_packages
66
+ prepare_command
67
+ end
68
+
69
+ def prepare_command_params
70
+ @prepared_command_params ||= begin
71
+ packages.map do |_name, package|
72
+ Rdm::SpecRunner::CommandGenerator.new(
73
+ package_name: package.name, package_path: package.path, spec_matcher: @spec_matcher
74
+ ).generate
75
+ end
76
+ end
77
+ end
78
+
79
+ def prepare_skipped_packages
80
+ prepared_command_params
81
+ .select { |cp| cp.spec_count == 0 }
82
+ .map { |cp| skipped_packages << cp.package_name }
83
+ end
84
+
85
+ def prepare_command
86
+ @command ||= begin
87
+ if @package_name
88
+ prepare_single_package_command(@package_name)
89
+ else
90
+ prepare_command_for_packages(prepared_command_params)
91
+ end
92
+ end
93
+ end
94
+
95
+ def prepare_single_package_command(package_name)
96
+ selected = prepared_command_params.select do |cmd_params|
97
+ cmd_params.package_name == package_name
98
+ end
99
+ prepare_command_for_packages(selected)
100
+ end
101
+
102
+ def prepare_command_for_packages(packages_command_params)
103
+ packages_command_params.select do |cmd_params|
104
+ cmd_params.spec_count > 0
105
+ end.sort_by do |cmd_params|
106
+ - cmd_params.spec_count
107
+ end.map(&:command).join(' && ')
108
+ end
109
+
110
+ def display_missing_specs
111
+ unless skipped_packages.empty?
112
+ print_message view.missing_specs_message(skipped_packages)
113
+ end
114
+ end
115
+
116
+ def execute_command
117
+ eval(command)
118
+ if !$?.success?
119
+ exit(1)
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,20 @@
1
+ class Rdm::SpecRunner::View
2
+ def packages_menu(prepared_command_params)
3
+ prepared_command_params
4
+ .sort_by(&:package_path)
5
+ .map { |x| " - #{x.package_name} (#{x.spec_count} spec files)" }
6
+ .join("\n")
7
+ end
8
+
9
+ def package_not_found_message(package_name, prepared_command_params)
10
+ "Package #{package_name} not found! \nPossible packages:\n\n#{packages_menu(prepared_command_params)}"
11
+ end
12
+
13
+ def missing_specs_message(skipped_packages)
14
+ "NO SPECS FOUND FOR PACKAGES: \n#{skipped_packages.map { |x| " - #{x}" }.join("\n")}\n\n**** SPECS *****: "
15
+ end
16
+
17
+ def no_specs_for_package(package_name)
18
+ "Package #{package_name} has no specs to execute!"
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ module Rdm
2
+ module RenderHelper
3
+ def camelize(string, uppercase_first_letter = true)
4
+ if uppercase_first_letter
5
+ string = string.sub(/^[a-z\d]*/) { $&.capitalize }
6
+ else
7
+ string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
8
+ end
9
+ string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV['RUBY_ENV'] = 'test'
4
+ require 'rdm'
5
+
6
+ REVISION = ARGV.clone.first
7
+ PATH = File.expand_path(__FILE__)
8
+
9
+ begin
10
+ changed_packages = Rdm::Handlers::DiffPackageHandler.handle(
11
+ path: PATH,
12
+ revision: REVISION
13
+ )
14
+
15
+ puts "No changed packages found!" if changed_packages.count == 0
16
+
17
+ changed_packages.each do |package|
18
+ Rdm::SpecRunner.run(
19
+ package: package,
20
+ path: PATH
21
+ )
22
+ end
23
+
24
+ rescue Rdm::Errors::GitRepositoryNotInitialized
25
+ puts "Git repository is not initialized. Use `git init .`"
26
+ exit(1)
27
+ end
28
+
29
+
@@ -15,218 +15,11 @@
15
15
  ENV['RUBY_ENV'] = 'test'
16
16
  require 'rdm'
17
17
 
18
- module SpecRunner
19
- class InputParams
20
- attr_accessor :package_name, :spec_matcher, :run_all
21
- def initialize(argv)
22
- @package_name = argv[0].to_s unless argv[0].nil?
23
- @spec_matcher = argv[1].to_s unless argv[1].nil?
24
- @run_all = !@package_name
25
- end
26
- end
27
-
28
- class CommandParams
29
- attr_accessor :package_name, :package_path, :spec_matcher, :spec_count, :command
30
- end
31
-
32
- class CommandGenerator
33
- attr_accessor :package_name, :package_path, :spec_matcher
34
- def initialize(package_name:, package_path:, spec_matcher:)
35
- @package_name = package_name
36
- @package_path = package_path
37
- @spec_matcher = spec_matcher
38
- end
39
-
40
- def spec_count
41
- Dir[File.join(package_path, 'spec/**/*_spec.rb')].size
42
- end
43
-
44
- def command
45
- "print_message(
46
- '**** Package: #{package_name} *****') \\
47
- && system('cd #{package_path} \\
48
- && bundle exec rspec --color --tty #{spec_matcher}', out: $stdout, err: :out)"
49
- end
50
-
51
- def generate
52
- CommandParams.new.tap do |cp|
53
- cp.package_name = package_name
54
- cp.package_path = package_path
55
- cp.command = command
56
- cp.spec_count = spec_count
57
- end
58
- end
59
- end
60
-
61
- class PackageFetcher
62
- def packages
63
- Rdm::SourceParser.read_and_init_source(rdm_packages_path).packages
64
- end
65
-
66
- def rdm_packages_path
67
- File.join(app_path, 'Rdm.packages')
68
- end
69
-
70
- def app_path
71
- File.join(File.dirname(__FILE__), '..')
72
- end
73
- end
74
-
75
- class View
76
- def packages_menu(prepared_command_params)
77
- prepared_command_params
78
- .sort_by(&:package_path)
79
- .map { |x| " - #{x.package_name} (#{x.spec_count} spec files)" }
80
- .join("\n")
81
- end
82
-
83
- def package_not_found_message(package_name, prepared_command_params)
84
- "Package #{package_name} not found! \nPossible packages:\n\n#{packages_menu(prepared_command_params)}"
85
- end
86
-
87
- def missing_specs_message(skipped_packages)
88
- "NO SPECS FOUND FOR PACKAGES: \n#{skipped_packages.map { |x| " - #{x}" }.join("\n")}\n\n**** SPECS *****: "
89
- end
90
-
91
- def no_specs_for_package(package_name)
92
- "Package #{package_name} has no specs to execute!"
93
- end
94
- end
95
-
96
- class Runner
97
- attr_accessor :input_params
98
- attr_accessor :skipped_packages
99
- attr_accessor :prepared_command_params
100
- attr_accessor :command
101
- def initialize(input_params)
102
- @input_params = input_params
103
- @skipped_packages = []
104
- end
105
-
106
- def run
107
- prepare!
108
- check_input_params!
109
- display_missing_specs
110
- execute_command
111
- end
112
-
113
- def packages
114
- @packages ||= PackageFetcher.new.packages
115
- end
116
-
117
- def view
118
- @view ||= View.new
119
- end
120
-
121
- def print_message(msg)
122
- puts msg
123
- true
124
- end
125
-
126
- def exit_with_message(msg)
127
- print_message(msg)
128
- exit 1
129
- end
130
-
131
- def check_input_params!
132
- if input_params.package_name
133
- unless is_package_included?(input_params.package_name)
134
- exit_with_message(
135
- view.package_not_found_message(input_params.package_name, prepared_command_params)
136
- )
137
- end
138
-
139
- if skipped_packages.include?(input_params.package_name)
140
- exit_with_message(
141
- view.no_specs_for_package(input_params.package_name)
142
- )
143
- end
144
- end
145
- end
146
-
147
- def is_package_included?(package_name)
148
- !prepared_command_params.select do |x|
149
- x.package_name == package_name
150
- end.empty?
151
- end
152
-
153
- def prepare!
154
- prepared_command_params = []
155
- skipped_packages = []
156
- command = nil
157
- prepare_command_params
158
- prepare_skipped_packages
159
- prepare_command
160
- end
161
-
162
- def prepare_command_params
163
- @prepared_command_params ||= begin
164
- packages.map do |_name, package|
165
- CommandGenerator.new(
166
- package_name: package.name, package_path: package.path, spec_matcher: spec_matcher
167
- ).generate
168
- end
169
- end
170
- end
171
-
172
- def prepare_skipped_packages
173
- prepared_command_params
174
- .select { |cp| cp.spec_count == 0 }
175
- .map { |cp| skipped_packages << cp.package_name }
176
- end
177
-
178
- def prepare_command
179
- @command ||= begin
180
- if input_params.package_name
181
- prepare_single_package_command(input_params.package_name)
182
- else
183
- prepare_command_for_packages(prepared_command_params)
184
- end
185
- end
186
- end
187
-
188
- def prepare_single_package_command(package_name)
189
- selected = prepared_command_params.select do |cmd_params|
190
- cmd_params.package_name == package_name
191
- end
192
- prepare_command_for_packages(selected)
193
- end
194
-
195
- def prepare_command_for_packages(packages_command_params)
196
- packages_command_params.select do |cmd_params|
197
- cmd_params.spec_count > 0
198
- end.sort_by do |cmd_params|
199
- - cmd_params.spec_count
200
- end.map(&:command).join(' && ')
201
- end
202
-
203
- def display_missing_specs
204
- unless skipped_packages.empty?
205
- print_message view.missing_specs_message(skipped_packages)
206
- end
207
- end
208
-
209
- def execute_command
210
- eval(command)
211
- exit(1) unless $CHILD_STATUS.success?
212
- end
213
-
214
- def spec_matcher
215
- input_params.spec_matcher || ''
216
- end
217
- end
218
-
219
- def self.run
220
- input_params = InputParams.new(ARGV.clone)
221
- Runner.new(input_params).run
222
- end
223
- end
224
-
225
18
  if ENV['TEST_RUN']
226
19
  require 'minitest/autorun'
227
- describe SpecRunner::Runner do
20
+ describe Rdm::SpecRunner::Runner do
228
21
  before do
229
- @runner = SpecRunner::Runner.new({})
22
+ @runner = Rdm::SpecRunner::Runner.new({})
230
23
  end
231
24
 
232
25
  describe 'works ' do
@@ -236,5 +29,9 @@ if ENV['TEST_RUN']
236
29
  end
237
30
  end
238
31
  else
239
- SpecRunner.run
32
+ Rdm::SpecRunner.run(
33
+ package: ARGV.clone.first,
34
+ spec_matcher: ARGV.clone.last,
35
+ path: File.expand_path(__FILE__)
36
+ )
240
37
  end