wagons 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +8 -8
  2. data/Rakefile +4 -6
  3. data/lib/generators/wagon/templates/%singular_name%.gemspec.tt +12 -11
  4. data/lib/generators/wagon/templates/{script → bin}/rails.tt +3 -2
  5. data/lib/generators/wagon/templates/config/routes.rb +1 -1
  6. data/lib/generators/wagon/templates/lib/%singular_name%/version.rb.tt +2 -2
  7. data/lib/generators/wagon/templates/lib/%singular_name%.rb.tt +0 -1
  8. data/lib/generators/wagon/wagon_generator.rb +4 -6
  9. data/lib/wagons/extensions/application.rb +2 -4
  10. data/lib/wagons/extensions/require_optional.rb +2 -2
  11. data/lib/wagons/extensions/test_case.rb +5 -7
  12. data/lib/wagons/installer.rb +52 -56
  13. data/lib/wagons/railtie.rb +2 -2
  14. data/lib/wagons/version.rb +1 -1
  15. data/lib/wagons/view_helper.rb +14 -16
  16. data/lib/wagons/wagon.rb +6 -8
  17. data/lib/wagons.rb +8 -10
  18. data/test/ci/rails3.gemfile.lock +108 -0
  19. data/test/dummy/Gemfile.lock +52 -48
  20. data/test/dummy/app/controllers/people_controller.rb +1 -3
  21. data/test/dummy/app/models/person.rb +1 -1
  22. data/test/dummy/config/application.rb +3 -4
  23. data/test/dummy/config/boot.rb +1 -1
  24. data/test/dummy/config/environments/development.rb +1 -1
  25. data/test/dummy/config/environments/production.rb +1 -1
  26. data/test/dummy/config/environments/test.rb +2 -2
  27. data/test/dummy/config/initializers/session_store.rb +1 -1
  28. data/test/dummy/config/initializers/wagon_app_version.rb +1 -1
  29. data/test/dummy/config/initializers/wrap_parameters.rb +1 -1
  30. data/test/dummy/config/routes.rb +3 -3
  31. data/test/dummy/db/development.sqlite3 +0 -0
  32. data/test/dummy/db/fixtures/development/people.rb +3 -3
  33. data/test/dummy/db/fixtures/test/people.rb +3 -3
  34. data/test/dummy/db/schema.rb +5 -5
  35. data/test/dummy/db/test.sqlite3 +0 -0
  36. data/test/dummy/log/development.log +1528 -1015
  37. data/test/dummy/log/test.log +11807 -6530
  38. data/test/dummy/test/models/person_test.rb +5 -5
  39. data/test/dummy/test/test_helper.rb +1 -1
  40. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  41. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  42. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  43. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  44. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  45. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  46. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  47. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  48. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  49. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  50. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  51. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  52. data/test/dummy/vendor/wagons/superliner/Gemfile.lock +53 -49
  53. data/test/dummy/vendor/wagons/superliner/app/controllers/cities_controller.rb +1 -2
  54. data/test/dummy/vendor/wagons/superliner/app/models/city.rb +2 -2
  55. data/test/dummy/vendor/wagons/superliner/db/fixtures/cities.rb +1 -1
  56. data/test/dummy/vendor/wagons/superliner/db/migrate/20120606125058_create_cities.rb +1 -1
  57. data/test/dummy/vendor/wagons/superliner/dummy_superliner.gemspec +11 -11
  58. data/test/dummy/vendor/wagons/superliner/lib/dummy_superliner/version.rb +2 -2
  59. data/test/dummy/vendor/wagons/superliner/lib/dummy_superliner/wagon.rb +3 -4
  60. data/test/dummy/vendor/wagons/superliner/lib/dummy_superliner.rb +1 -1
  61. data/test/dummy/vendor/wagons/superliner/script/rails +1 -1
  62. data/test/dummy/vendor/wagons/superliner/test/controllers/cities_controller_test.rb +5 -7
  63. data/test/dummy/vendor/wagons/superliner/test/controllers/people_controller_test.rb +2 -4
  64. data/test/dummy/vendor/wagons/superliner/test/models/city_test.rb +3 -3
  65. data/test/dummy/vendor/wagons/superliner/test/models/person_test.rb +5 -7
  66. data/test/dummy/vendor/wagons/superliner/test/test_helper.rb +1 -2
  67. data/test/dummy/vendor/wagons/superliner/test/wagon_test.rb +23 -24
  68. data/test/test_helper.rb +5 -5
  69. data/test/wagons_installer_test.rb +72 -75
  70. data/test/wagons_test.rb +1 -1
  71. metadata +174 -160
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTFiMDFkZWY5ZjY1MzE2MjRkYjlkZmJlNTZkMDY5MWYyNWEwNmNlYQ==
4
+ YTA2ZTc4NjkwNWJjZTU1YTZkNTE0MTY2MTg4MTMzYWMwMjU4N2ZhYQ==
5
5
  data.tar.gz: !binary |-
6
- ZmQ3NzYzYTU5MzA4YmIyY2E1ZDcwMTVmOTk5Y2FiNTJlOTkxZWQzZA==
6
+ NTBhOTYzY2UxNDAxNzk0YjlkZjA1OTFkMDNlMjkwMGQ3NmY1YmI5ZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDk4NzUwMjRmNmQzNDA1ODQ4Mjk2ZGIyMDVlMmExZjc5MmY3YjNkNzY2ZmVi
10
- ZWQ2ZWI2ZDVlOGI0ZjdkZTZkYWU4NTVjNTgwMjEyMWZmZTU5OWIyNDA1YjA2
11
- MGFiN2FiZjQzMzA4M2ZiM2RhZmMxMmUwZDQ2Mzc3YmUzZGY1YzQ=
9
+ NzQzZWZhMGJjNmVkNzQ3OGRhMTRkOWZkMTNjZmVkZWZjNzU1ZjNkYzU0MjFl
10
+ NzliMGU5ZWRjNGQ3MDc2NTFhYzVmMjgwMDA1Y2QwNDM4MDdjZTg1OTMwODFh
11
+ NDhhOGMyNzU0ZGFmZWM5NGZiYjM0OGI2NTI5ODZlOWY5NWMyMzA=
12
12
  data.tar.gz: !binary |-
13
- NTNlNTIwYjdlYWUzZTU3MGE3NDAwNmZkODQ1NTY0ZjU3ZDQ0MWJhMDVlMWEw
14
- OWYxODE3ZDRkMzkwYThjYzA4NzU1NjUwYjJmZGZlYmM2YjVjODQ3NjcxNDU2
15
- N2IwMGJhZGU5ODY3ZTQzZDM1NTQ0YjZkZTcwYWM0ZDgwYTQ0MDE=
13
+ M2I0MWExOWI1YzE5Njk0MTg1M2JmZDk3ZjU4MjBlMWUyNjg3NTE4YWI3MzI4
14
+ ZWUwN2Q2ZmQ0ZTFmZGZlYjM4MTdjNzY5ZGU3YmNlNjhhN2U5YTk0YjNmMWE0
15
+ MDQ3ZDQ3MDBkNmJiYmNiMzI0MmJjNjkwNDNkNDBjMDZjNjMwMmI=
data/Rakefile CHANGED
@@ -21,7 +21,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
21
21
  rdoc.rdoc_files.include('lib/**/*.rb')
22
22
  end
23
23
 
24
-
25
24
  Bundler::GemHelper.install_tasks
26
25
 
27
26
  require 'rake/testtask'
@@ -33,14 +32,13 @@ end
33
32
 
34
33
  task :test do
35
34
  begin
36
- Bundler.with_clean_env { sh "cd test/dummy && rails g wagon test_wagon" }
37
- Bundler.with_clean_env { sh "cd test/dummy && bundle exec rake wagon:bundle:update" }
35
+ Bundler.with_clean_env { sh 'cd test/dummy && rails g wagon test_wagon' }
36
+ Bundler.with_clean_env { sh 'cd test/dummy && bundle exec rake wagon:bundle:update' }
38
37
  Bundler.with_clean_env { sh "cd test/dummy && bundle exec rake db:migrate test #{'-t' if Rake.application.options.trace}" }
39
38
  Bundler.with_clean_env { sh "cd test/dummy && bundle exec rake wagon:test #{'-t' if Rake.application.options.trace}" }
40
39
  ensure
41
- sh "rm -rf test/dummy/vendor/wagons/test_wagon"
40
+ sh 'rm -rf test/dummy/vendor/wagons/test_wagon'
42
41
  end
43
42
  end
44
43
 
45
- task :default => :test
46
-
44
+ task default: :test
@@ -1,19 +1,20 @@
1
- $:.push File.expand_path("../lib", __FILE__)
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
2
 
3
3
  # Maintain your wagon's version:
4
- require "<%= singular_name %>/version"
4
+ require '<%= singular_name %>/version'
5
5
 
6
6
  # Describe your gem and declare its dependencies:
7
7
  Gem::Specification.new do |s|
8
- s.name = "<%= singular_name %>"
8
+ # rubocop:disable SingleSpaceBeforeFirstArg
9
+ s.name = '<%= singular_name %>'
9
10
  s.version = <%= class_name %>::VERSION
10
- s.authors = ["Your name"]
11
- s.email = ["Your email"]
12
- #s.homepage = "TODO"
13
- s.summary = "<%= wagon_name.humanize.titleize %>"
14
- s.description = "Wagon description"
15
-
16
- s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile"]
17
- s.test_files = Dir["test/**/*"]
11
+ s.authors = ['Your name']
12
+ s.email = ['Your email']
13
+ # s.homepage = 'TODO'
14
+ s.summary = '<%= wagon_name.humanize.titleize %>'
15
+ s.description = 'Wagon description'
18
16
 
17
+ s.files = Dir['{app,config,db,lib}/**/*'] + ['Rakefile']
18
+ s.test_files = Dir['test/**/*']
19
+ # rubocop:enable SingleSpaceBeforeFirstArg
19
20
  end
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
2
+ # This command will automatically be run when you run "rails" with Rails
3
+ # gems installed from the root of your application.
3
4
 
4
5
  ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
6
 
@@ -8,4 +9,4 @@ ENGINE_PATH = File.expand_path('lib/<%= singular_name %>/engine', ENGINE_ROOT)
8
9
 
9
10
  load File.expand_path('../../app_root.rb', __FILE__)
10
11
 
11
- load File.expand_path('script/rails', ENV["APP_ROOT"])
12
+ load File.expand_path('script/rails', ENV['APP_ROOT'])
@@ -1,3 +1,3 @@
1
1
  Rails.application.routes.draw do
2
-
2
+
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module <%= class_name %>
2
- VERSION = "0.0.1"
3
- end
2
+ VERSION = '0.0.1'
3
+ end
@@ -4,4 +4,3 @@ require '<%= singular_name %>/wagon'
4
4
 
5
5
  module <%= class_name %>
6
6
  end
7
-
@@ -1,5 +1,4 @@
1
1
  class WagonGenerator < Rails::Generators::NamedBase #:nodoc:
2
-
3
2
  attr_reader :wagon_name
4
3
 
5
4
  source_root File.expand_path('../templates', __FILE__)
@@ -28,11 +27,10 @@ class WagonGenerator < Rails::Generators::NamedBase #:nodoc:
28
27
  private
29
28
 
30
29
  def all_templates
31
- source_paths.collect do |path|
32
- Dir[File.join(path, "**", "{*,.[a-z]*}")].
33
- select {|f| File.file?(f) }.
34
- collect {|f| f.sub(path + File::SEPARATOR, '') }
30
+ source_paths.map do |path|
31
+ Dir[File.join(path, '**', '{*,.[a-z]*}')].
32
+ select { |f| File.file?(f) }.
33
+ map { |f| f.sub(path + File::SEPARATOR, '') }
35
34
  end.flatten.uniq.sort
36
35
  end
37
-
38
36
  end
@@ -1,6 +1,5 @@
1
1
  module Rails
2
2
  class Application < Engine
3
-
4
3
  protected
5
4
 
6
5
  # Append wagons at the end of all railties, even after the application.
@@ -11,8 +10,7 @@ module Rails
11
10
  end
12
11
  end
13
12
  end
14
-
13
+
15
14
  alias_method_chain :ordered_railties, :wagons
16
-
17
15
  end
18
- end
16
+ end
@@ -5,5 +5,5 @@ class Object
5
5
  rescue LoadError
6
6
  # that's fine, it's an optional require
7
7
  end
8
- alias optional_require require_optional
9
- end
8
+ alias_method :optional_require, :require_optional
9
+ end
@@ -1,13 +1,11 @@
1
1
  module ActiveSupport #:nodoc:
2
2
  class TestCase
3
-
4
3
  # Resets the fixtures to the new path
5
4
  def self.reset_fixture_path(path)
6
- self.fixture_table_names = []
7
- self.fixture_class_names = {}
8
- self.fixture_path = path
9
- self.fixtures :all
5
+ self.fixture_table_names = []
6
+ self.fixture_class_names = {}
7
+ self.fixture_path = path
8
+ fixtures :all
10
9
  end
11
-
12
10
  end
13
- end
11
+ end
@@ -1,21 +1,19 @@
1
1
  module Wagons
2
-
3
2
  # Helper class to install wagons into the current application.
4
3
  # Wagons are searched for in the system gem repository.
5
4
  #
6
5
  # If you want to use the #install method, add "gem 'open4'" to
7
6
  # your Gemfile.
8
7
  class Installer
9
-
10
8
  attr_accessor :include_version_in_wagonfile
11
-
9
+
12
10
  def initialize
13
11
  @include_version_in_wagonfile = true
14
12
  end
15
-
13
+
16
14
  # Gem specifications of all installed wagons.
17
15
  def installed
18
- @installed ||= Wagons.all.collect(&:gemspec)
16
+ @installed ||= Wagons.all.map(&:gemspec)
19
17
  end
20
18
 
21
19
  # Most recent gem specifications of all wagons available in GEM_HOME.
@@ -25,19 +23,18 @@ module Wagons
25
23
  # only keep most recent version in @available
26
24
  @available = []
27
25
  load_available_specs.each do |spec|
28
- if prev = @available.find {|w| w.name == spec.name }
26
+ if prev = @available.find { |w| w.name == spec.name }
29
27
  if prev.version < spec.version
30
- @available.delete(prev)
31
- @available << spec
28
+ @available.delete(prev)
29
+ @available << spec
32
30
  end
33
31
  else
34
- @available << spec
32
+ @available << spec
35
33
  end
36
34
  end
37
35
  @available
38
36
  end
39
37
 
40
-
41
38
  # Most recent gem specifications of available, but not installed (in any version) wagons.
42
39
  def not_installed
43
40
  exclude_specs(available, installed)
@@ -59,9 +56,9 @@ module Wagons
59
56
  # This method requires open4.
60
57
  def install(names)
61
58
  change_internal(names, :check_dependencies) do |specs|
62
- content = File.read(wagonfile) rescue ""
59
+ content = File.read(wagonfile) rescue ''
63
60
  wagonfile_update(specs)
64
-
61
+
65
62
  begin
66
63
  setup_wagons(specs)
67
64
  rescue => e
@@ -72,7 +69,7 @@ module Wagons
72
69
  end
73
70
 
74
71
  # Remove the wagons with the given names. I.e., reverts the migrations
75
- # of the given wagon names if the wagon is not protected
72
+ # of the given wagon names if the wagon is not protected
76
73
  # and removes the entries from the Wagonfile.
77
74
  # Returns nil if everything is fine or a string with error messages.
78
75
  def uninstall(names)
@@ -85,20 +82,20 @@ module Wagons
85
82
  # Get the gem specification of the installed wagon with the given name.
86
83
  # Return nil if not found.
87
84
  def installed_spec(name)
88
- installed.find {|s| s.name == name }
85
+ installed.find { |s| s.name == name }
89
86
  end
90
87
 
91
88
  # Get the gem specification of an available wagon with the given name.
92
89
  # Return nil if not found.
93
90
  def available_spec(name)
94
- available.find {|s| s.name == name}
91
+ available.find { |s| s.name == name }
95
92
  end
96
-
93
+
97
94
  # Update the Wagonfile with the given gem specifications.
98
95
  def wagonfile_update(specs)
99
96
  wagonfile_edit(specs) do |spec, content|
100
97
  declaration = "gem '#{spec.name}'"
101
- declaration += ", '#{spec.version.to_s}'" if include_version_in_wagonfile
98
+ declaration += ", '#{spec.version}'" if include_version_in_wagonfile
102
99
  unless content.sub!(gem_declaration_regexp(spec.name), declaration)
103
100
  content += "\n#{declaration}"
104
101
  end
@@ -112,7 +109,7 @@ module Wagons
112
109
  content.sub(gem_declaration_regexp(spec.name), '')
113
110
  end
114
111
  end
115
-
112
+
116
113
  # Check if all wagon dependencies of the given gem specifications
117
114
  # are met by the installed wagons.
118
115
  # Returns nil if everything is fine or a string with error messages.
@@ -124,7 +121,7 @@ module Wagons
124
121
 
125
122
  check_all_dependencies(specs, future, missing)
126
123
  end
127
-
124
+
128
125
  # Check if the app requirement of the given gem specifications
129
126
  # are met by the current app version.
130
127
  # Returns nil if everything is fine or a array with error messages.
@@ -140,7 +137,7 @@ module Wagons
140
137
 
141
138
  missing
142
139
  end
143
-
140
+
144
141
  # Check if the wagon dependencies of the remaining wagons
145
142
  # would still be met after the given gem specifications are uninstalled.
146
143
  # Returns nil if everything is fine or a string with error messages.
@@ -163,47 +160,47 @@ module Wagons
163
160
  # List of available gem specifications with the given names.
164
161
  # Raises an error if a name cannot be found.
165
162
  def specs_from_names(names)
166
- names.collect do |name|
163
+ names.map do |name|
167
164
  spec = available_spec(name)
168
- raise "#{name} was not found" if spec.nil?
165
+ fail "#{name} was not found" if spec.nil?
169
166
  spec
170
167
  end
171
168
  end
172
-
169
+
173
170
  # Removes all gem specifications with the same name in to_be_excluded from full.
174
171
  # Versions are ignored.
175
172
  def exclude_specs(full, to_be_excluded)
176
- full.clone.delete_if {|s| to_be_excluded.find {|d| s.name == d.name } }
173
+ full.clone.delete_if { |s| to_be_excluded.find { |d| s.name == d.name } }
177
174
  end
178
-
175
+
179
176
  # Wagonfile
180
177
  def wagonfile
181
- Rails.root.join("Wagonfile")
178
+ Rails.root.join('Wagonfile')
182
179
  end
183
-
180
+
184
181
  # The wagon class of the given spec.
185
182
  def wagon_class(spec)
186
183
  @wagon_classes ||= {}
187
- return @wagon_classes[spec] if @wagon_classes.has_key?(spec)
188
-
184
+ return @wagon_classes[spec] if @wagon_classes.key?(spec)
185
+
189
186
  clazz = nil
190
187
  file = File.join(spec.gem_dir, 'lib', spec.name, 'wagon.rb')
191
- if File.exists?(file)
188
+ if File.exist?(file)
192
189
  require file
193
190
  clazz = "#{spec.name.camelize}::Wagon".constantize
194
191
  else
195
- raise "#{spec.name} wagon class not found in #{file}"
192
+ fail "#{spec.name} wagon class not found in #{file}"
196
193
  end
197
194
  @wagon_classes[spec] = clazz
198
195
  end
199
196
 
200
197
  private
201
-
198
+
202
199
  def load_available_specs
203
200
  paths = [ENV['GEM_HOME']]
204
- paths += (ENV['GEM_PATH'] || "").split(File::PATH_SEPARATOR)
205
- paths.collect(&:presence).compact.collect do |path|
206
- Dir[File.join(path, 'specifications', "#{Wagons.app_name}_*.gemspec")].collect do |gemspec|
201
+ paths += (ENV['GEM_PATH'] || '').split(File::PATH_SEPARATOR)
202
+ paths.map(&:presence).compact.map do |path|
203
+ Dir[File.join(path, 'specifications', "#{Wagons.app_name}_*.gemspec")].map do |gemspec|
207
204
  Gem::Specification.load(gemspec)
208
205
  end
209
206
  end.flatten
@@ -222,7 +219,7 @@ module Wagons
222
219
  to_check.each do |spec|
223
220
  spec.runtime_dependencies.each do |dep|
224
221
  if dep.name.start_with?("#{Wagons.app_name}_") &&
225
- all.none? {|s| dep.matches_spec?(s) }
222
+ all.none? { |s| dep.matches_spec?(s) }
226
223
  missing << "#{spec.name} requires #{dep.name} #{dep.requirement}"
227
224
  end
228
225
  end
@@ -230,13 +227,13 @@ module Wagons
230
227
 
231
228
  missing.join("\n").presence
232
229
  end
233
-
230
+
234
231
  def gem_declaration_regexp(name)
235
232
  /^.*gem\s+('|")#{name}('|").*$/
236
233
  end
237
-
234
+
238
235
  def wagonfile_edit(specs)
239
- content = File.read(wagonfile) rescue ""
236
+ content = File.read(wagonfile) rescue ''
240
237
 
241
238
  specs.each do |spec|
242
239
  content = yield spec, content
@@ -245,69 +242,68 @@ module Wagons
245
242
 
246
243
  wagonfile_write(content.strip)
247
244
  end
248
-
245
+
249
246
  def wagonfile_write(content)
250
247
  File.open(wagonfile, 'w') do |f|
251
248
  f.puts content
252
249
  end
253
250
  end
254
-
251
+
255
252
  def setup_wagons(specs)
256
253
  require 'open4'
257
-
254
+
258
255
  env = Rails.env
259
256
  cmd = setup_command(specs)
260
257
  Rails.logger.info(cmd)
261
-
258
+
262
259
  Bundler.with_clean_env do
263
260
  ENV['RAILS_ENV'] = env
264
261
  execute_setup(cmd)
265
262
  end
266
263
  end
267
-
264
+
268
265
  def remove_wagons(specs)
269
266
  Wagons.all.reverse.each do |wagon|
270
- if specs.find {|spec| wagon.gem_name == spec.name }
267
+ if specs.find { |spec| wagon.gem_name == spec.name }
271
268
  wagon.unload_seed
272
269
  wagon.revert
273
270
  end
274
271
  end
275
272
  end
276
-
273
+
277
274
  def setup_command(specs)
278
- wagons = specs.collect {|s| s.name.sub(/^#{Wagons.app_name}_/, '') }.join(',')
275
+ wagons = specs.map { |s| s.name.sub(/^#{Wagons.app_name}_/, '') }.join(',')
279
276
  "cd #{Rails.root} && bundle exec rake wagon:setup WAGON=#{wagons} -t"
280
277
  end
281
-
278
+
282
279
  def execute_setup(cmd)
283
280
  msg = nil
284
281
  status = Open4.popen4(cmd) do |pid, input, output, errors|
285
282
  msg = errors.read
286
283
  end
287
-
284
+
288
285
  if status.exitstatus.to_i != 0
289
- raise msg.presence || "Unknown error while running wagon:setup"
286
+ fail msg.presence || 'Unknown error while running wagon:setup'
290
287
  end
291
288
  end
292
-
289
+
293
290
  def change_internal(names, *checks)
294
291
  specs = specs_from_names(names)
295
-
292
+
296
293
  if msg = perform_checks(specs, checks)
297
294
  msg
298
295
  else
299
296
  yield specs
300
297
  nil
301
298
  end
302
- rescue Exception => e
299
+ rescue => e
303
300
  handle_exception(e, names)
304
301
  end
305
-
302
+
306
303
  def handle_exception(e, names)
307
304
  msg = e.message
308
305
  Rails.logger.error msg + "\n\t" + e.backtrace.join("\n\t")
309
306
  msg
310
307
  end
311
-
312
308
  end
313
- end
309
+ end
@@ -2,7 +2,7 @@ module Wagons
2
2
  # Integrate tasks into Rails.
3
3
  class Railtie < Rails::Railtie #:nodoc:
4
4
  rake_tasks do
5
- load "tasks/wagons.rake"
5
+ load 'tasks/wagons.rake'
6
6
  end
7
7
  end
8
- end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Wagons
2
- VERSION = "0.2.2"
2
+ VERSION = '0.3.0'
3
3
  end
@@ -1,55 +1,54 @@
1
1
  module Wagons
2
2
  module ViewHelper
3
-
4
3
  # Renders all partials with names that match "_[ key ]_*.[ format ].[ handler ]"
5
4
  # in alphabetical order.
6
5
  # Accepts an additional option :folder to pass an additional folder to search
7
6
  # extension partials in.
8
7
  def render_extensions(key, options = {})
9
- extensions = find_extension_partials(key, options.delete(:folder)).collect do |partial|
10
- render options.merge(:partial => partial)
8
+ extensions = find_extension_partials(key, options.delete(:folder)).map do |partial|
9
+ render options.merge(partial: partial)
11
10
  end
12
11
  safe_join(extensions)
13
12
  end
14
-
13
+
15
14
  # The view folders relative to app/views in which extensions are searched for.
16
15
  # Uses the folder of the current template.
17
16
  def extension_folders
18
17
  [current_template_folder]
19
18
  end
20
-
19
+
21
20
  # The folder of the current partial relative to app/views
22
21
  def current_template_folder
23
22
  @virtual_path[/(.+)\/.*/, 1]
24
23
  end
25
-
24
+
26
25
  private
27
-
26
+
28
27
  def find_extension_partials(key, folder = nil)
29
28
  folders = extension_folders.dup
30
29
  folders << folder if folder
31
-
30
+
32
31
  files = find_extension_files(key, folders).sort_by { |f| File.basename(f) }
33
32
  files_to_partial_names(files)
34
33
  end
35
-
34
+
36
35
  def find_extension_files(key, folders)
37
36
  folder_pattern = glob_pattern(folders)
38
37
  formats = glob_pattern(lookup_context.formats)
39
38
  handlers = glob_pattern(lookup_context.handlers)
40
-
41
- view_paths.collect do |path|
39
+
40
+ view_paths.map do |path|
42
41
  Dir.glob(File.join(path.to_s, folder_pattern, "_#{key}_*.#{formats}.#{handlers}"))
43
42
  end.flatten
44
43
  end
45
-
44
+
46
45
  def files_to_partial_names(files)
47
- files.collect do |f|
46
+ files.map do |f|
48
47
  m = f.match(/views.(.+?[\/\\])_(.+)\.\w+\.\w+$/)
49
48
  m[1] + m[2]
50
49
  end
51
50
  end
52
-
51
+
53
52
  def glob_pattern(list)
54
53
  if list.size == 1
55
54
  list.first
@@ -57,8 +56,7 @@ module Wagons
57
56
  "{#{list.join(',')}}"
58
57
  end
59
58
  end
60
-
61
59
  end
62
60
  end
63
61
 
64
- ActionView::Base.send(:include, Wagons::ViewHelper) if defined?(ActionView::Base)
62
+ ActionView::Base.send(:include, Wagons::ViewHelper) if defined?(ActionView::Base)
data/lib/wagons/wagon.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'active_support/concern'
2
2
 
3
3
  module Wagons
4
-
5
4
  # A wagon is an extension to your application train running on Rails.
6
5
  #
7
6
  # Wagons are built on Rails Engines. To change an engine to a wagon,
@@ -37,14 +36,14 @@ module Wagons
37
36
 
38
37
  # Direct dependencies on other wagons.
39
38
  def dependencies
40
- gemspec.dependencies.collect(&:name).
41
- select {|dep| dep =~ /\A#{Wagons.app_name}_/ }.
42
- collect { |dep| Wagons.find(dep) || raise("No wagon #{dep} found") }
39
+ gemspec.dependencies.map(&:name).
40
+ select { |dep| dep =~ /\A#{Wagons.app_name}_/ }.
41
+ map { |dep| Wagons.find(dep) || fail("No wagon #{dep} found") }
43
42
  end
44
43
 
45
44
  # Recursive depdencies on other wagons.
46
45
  def all_dependencies
47
- dependencies.collect {|dep| dep.all_dependencies + [dep] }.flatten.uniq
46
+ dependencies.map { |dep| dep.all_dependencies + [dep] }.flatten.uniq
48
47
  end
49
48
 
50
49
  # Gem Specification.
@@ -103,8 +102,8 @@ module Wagons
103
102
  end
104
103
 
105
104
  extend Rake::DSL if defined? Rake::DSL
106
- self.class.rake_tasks.each { |block| self.instance_exec(app, &block) }
107
- paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
105
+ self.class.rake_tasks.each { |block| instance_exec(app, &block) }
106
+ paths['lib/tasks'].existent.sort.each { |ext| load(ext) }
108
107
  self
109
108
  end
110
109
 
@@ -129,4 +128,3 @@ module Wagons
129
128
  end
130
129
  end
131
130
  end
132
-
data/lib/wagons.rb CHANGED
@@ -10,7 +10,6 @@ require 'wagons/extensions/application'
10
10
  require 'wagons/extensions/require_optional'
11
11
  require 'wagons/extensions/test_case'
12
12
 
13
-
14
13
  # Utility class to find single wagons and provide additional information
15
14
  # about the main application.
16
15
  module Wagons
@@ -18,37 +17,36 @@ module Wagons
18
17
  def self.all
19
18
  enumerable = Rails.application.railties
20
19
  enumerable = enumerable.all if enumerable.respond_to?(:all)
21
- enumerable.select {|r| r.is_a?(Wagon) }
20
+ enumerable.select { |r| r.is_a?(Wagon) }
22
21
  end
23
-
22
+
24
23
  # Find a wagon by its name.
25
24
  def self.find(name)
26
25
  name = name.to_s
27
- all.find {|wagon| wagon.wagon_name == name || wagon.gem_name == name }
26
+ all.find { |wagon| wagon.wagon_name == name || wagon.gem_name == name }
28
27
  end
29
-
28
+
30
29
  # The name of the main Rails application.
31
30
  # By default, this is the underscored name of the application module.
32
31
  # This name is directly used for the gem names,
33
32
  def self.app_name
34
33
  @app_name ||= Rails.application.class.name.split('::').first.underscore
35
34
  end
36
-
35
+
37
36
  # Set the application name. Should be lowercase with underscores.
38
37
  # Do this in an initializer.
39
38
  def self.app_name=(name)
40
39
  @app_name = name
41
40
  end
42
-
41
+
43
42
  # The version of the main application.
44
43
  def self.app_version
45
- @app_version ||= Gem::Version.new("0")
44
+ @app_version ||= Gem::Version.new('0')
46
45
  end
47
-
46
+
48
47
  # Set the version of the main application.
49
48
  # Do this in an initializer.
50
49
  def self.app_version=(version)
51
50
  @app_version = version.is_a?(Gem::Version) ? version : Gem::Version.new(version)
52
51
  end
53
52
  end
54
-