rdm 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 030a4105373d24a3ba5d97a52cb34d0bf2c79d2f
4
- data.tar.gz: af38a6d0eeb9354bfe33d1beba9c1d289b75fcd5
3
+ metadata.gz: 66772ce18f205894e338d4488a739f64251fc1a7
4
+ data.tar.gz: 787ec81e2d74245cb9c7e8344da6638e4a27a731
5
5
  SHA512:
6
- metadata.gz: d042a73c45f127800653f8dab0fc5a4cb40c5ab1fdddd0a1c842e2579c245205523389d751099b301a128b89eea3e59a896998ee9764e341b682e0f6c4ece6c3
7
- data.tar.gz: 056d522dc8c85d7ebfe1450ad119431bda4e33ccf54c7e0a015ff9c749f0c2de4328836b700f6e32757941a9f25e04e946339825ae632c4d800a4f6ffebdac2d
6
+ metadata.gz: e14981c363eb19b7c2bd57feaa3af786421821db7872d266132929d70e9555475a9a06d8cd385a9bee808191ab2422d48070c9bdcade6fff0f3c64e7dca9615e
7
+ data.tar.gz: c3525e1e6ad865d092fe46dab42b7e676864c6e4e8455d861b98f0eaccda2321eaadbba0f233c712efa76dbae70bfb3afdd788a9269ccfb7c310dd0fcb496538
data/bin/rdm-generate CHANGED
@@ -46,8 +46,8 @@ puts "Generating package #{package_name} to #{options[:path]}"
46
46
 
47
47
  begin
48
48
  Rdm::PackageGenerator.generate_package(current_dir, package_name, options[:path], options[:skip_rspec])
49
- rescue Errno::ENOENT
50
- puts "#{Rdm::SOURCE_FILENAME} not found. Please run on directory containing #{Rdm::SOURCE_FILENAME}"
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
51
  rescue Rdm::Errors::PackageExists
52
52
  puts "Error. Package already exist. Package was not generated"
53
53
  rescue Rdm::Errors::PackageDirExists
data/bin/rdm-install CHANGED
@@ -8,6 +8,6 @@ require 'rdm'
8
8
  source_path = File.join(`pwd`.chomp, Rdm::SOURCE_FILENAME)
9
9
  begin
10
10
  Rdm::SourceInstaller.install(source_path)
11
- rescue Errno::ENOENT
12
- puts "#{Rdm::SOURCE_FILENAME} not found. Please run on directory containing #{Rdm::SOURCE_FILENAME}"
13
- end
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.rb CHANGED
@@ -15,6 +15,7 @@ module Rdm
15
15
  require "rdm/config"
16
16
  require "rdm/config_scope"
17
17
  require "rdm/config_manager"
18
+ require "rdm/auto_updater"
18
19
 
19
20
  class << self
20
21
  # Initialize current package using Package.rb
@@ -0,0 +1,41 @@
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
data/lib/rdm/errors.rb CHANGED
@@ -5,5 +5,8 @@ module Rdm
5
5
 
6
6
  class PackageDirExists < StandardError
7
7
  end
8
+
9
+ class SourceFileDoesNotExist < StandardError
10
+ end
8
11
  end
9
12
  end
@@ -49,6 +49,7 @@ class Rdm::PackageGenerator
49
49
 
50
50
  Dir.chdir(current_dir) do
51
51
  ensure_file([package_relative_path, '.gitignore'])
52
+ ensure_file([package_relative_path, package_subdir_name, package_name, '.gitignore'])
52
53
  ensure_file(
53
54
  [package_relative_path, package_subdir_name, "#{package_name}.rb"],
54
55
  template_content("main_module_file.rb.erb", {package_name_camelized: package_name.camelize})
@@ -8,6 +8,7 @@ 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
+ ensure_updated(package_path)
11
12
  if File.directory?(package_path)
12
13
  package_path = File.join(package_path, Rdm::PACKAGE_LOCK_FILENAME)
13
14
  end
@@ -25,6 +26,10 @@ class Rdm::PackageImporter
25
26
  package
26
27
  end
27
28
 
29
+ def ensure_updated(package_path)
30
+ Rdm::AutoUpdater.update(package_path)
31
+ end
32
+
28
33
  # Import package and initialize module
29
34
  def import_package(package_name, source:, imported_packages: [], imported_configs: [], group: nil)
30
35
  return if imported_packages.include?(package_name.to_s)
@@ -1,8 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "bundler/setup"
3
3
  require "rdm"
4
+
5
+ ENV["RUBY_ENV"] ||= "development"
4
6
  Rdm.init(File.expand_path('../../', __FILE__))
5
7
 
8
+
6
9
  # You can add fixtures and/or initialization code here to make experimenting
7
10
  # with your gem easier. You can also use a different console, if you like.
8
11
 
@@ -0,0 +1,244 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ## # run own tests:
4
+ ## $ TEST_RUN=1 tests/run
5
+
6
+ ## # run application tests:
7
+ ## $ tests/run
8
+
9
+ ## # run package tests:
10
+ ## $ tests/run commands
11
+
12
+ ## # run spec in a package:
13
+ ## $ tests/run commands some_spec.rb
14
+
15
+ ENV['RUBY_ENV'] = 'test'
16
+ require 'rdm'
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 if !argv[0].nil?
23
+ @spec_matcher = argv[1].to_s if !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{|x| x.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
+ if not 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{|x|
149
+ x.package_name == package_name
150
+ }.size > 0
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{|name, package|
165
+ CommandGenerator.new(
166
+ package_name: package.name, package_path: package.path, spec_matcher: spec_matcher
167
+ ).generate
168
+ }
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{|cmd_params|
190
+ cmd_params.package_name == package_name
191
+ }
192
+ prepare_command_for_packages(selected)
193
+ end
194
+
195
+ def prepare_command_for_packages(packages_command_params)
196
+ packages_command_params.select{|cmd_params|
197
+ cmd_params.spec_count > 0
198
+ }.sort_by{|cmd_params|
199
+ - cmd_params.spec_count
200
+ }.map{|cmd_params|
201
+ cmd_params.command
202
+ }.join(" && ")
203
+ end
204
+
205
+ def display_missing_specs
206
+ if !skipped_packages.empty?
207
+ print_message view.missing_specs_message(skipped_packages)
208
+ end
209
+ end
210
+
211
+ def execute_command
212
+ eval(command)
213
+ if !$?.success?
214
+ exit(1)
215
+ end
216
+ end
217
+
218
+ def spec_matcher
219
+ input_params.spec_matcher || ""
220
+ end
221
+ end
222
+
223
+ def self.run
224
+ input_params = InputParams.new(ARGV.clone)
225
+ Runner.new(input_params).run
226
+ end
227
+ end
228
+
229
+ unless ENV["TEST_RUN"]
230
+ SpecRunner.run
231
+ else
232
+ require "minitest/autorun"
233
+ describe SpecRunner::Runner do
234
+ before do
235
+ @runner = SpecRunner::Runner.new({})
236
+ end
237
+
238
+ describe "works " do
239
+ it "assert true" do
240
+ assert 2 == 2
241
+ end
242
+ end
243
+ end
244
+ end
data/lib/rdm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rdm
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.12"
3
3
  end
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.1.11
4
+ version: 0.1.12
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-12-07 00:00:00.000000000 Z
11
+ date: 2016-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -101,6 +101,7 @@ files:
101
101
  - example/server/package/server.rb
102
102
  - example/server/server.rb
103
103
  - lib/rdm.rb
104
+ - lib/rdm/auto_updater.rb
104
105
  - lib/rdm/config.rb
105
106
  - lib/rdm/config_manager.rb
106
107
  - lib/rdm/config_scope.rb
@@ -119,6 +120,7 @@ files:
119
120
  - lib/rdm/templates/main_module_file.rb.erb
120
121
  - lib/rdm/templates/package.rb.erb
121
122
  - lib/rdm/templates/spec/spec_helper.rb
123
+ - lib/rdm/templates/tests/run
122
124
  - lib/rdm/version.rb
123
125
  - rdm.gemspec
124
126
  - spec/fixtures/SampleSource.rb