Engine Generator

December 21st, 2005

Jon Lim on the Rails mailing list just announced the release of Engines Generator.

From the documentation:
$ script/generate engine UploadEngine
Please enter the author's name: Joe Smith
Please enter the author's email: joe.smith@xyz.com

We can generate the following licenses automatically for you:
0) None
1) GPL
2) MIT
3) LGPL
Please select a license: 2
'MIT' selected
      exists  vendor/plugins
      create  vendor/plugins/upload_engine
      create  vendor/plugins/upload_engine/README
      create  vendor/plugins/upload_engine/init_engine.rb
      create  vendor/plugins/upload_engine/app
      create  vendor/plugins/upload_engine/app/models
      create  vendor/plugins/upload_engine/app/controllers
      create  vendor/plugins/upload_engine/app/helpers
      create  vendor/plugins/upload_engine/app/views
      create  vendor/plugins/upload_engine/db
      create  vendor/plugins/upload_engine/db/migrate
      create  vendor/plugins/upload_engine/lib
      create  vendor/plugins/upload_engine/lib/upload_engine.rb
      create  vendor/plugins/upload_engine/lib/upload_engine
      create  vendor/plugins/upload_engine/public
      create  vendor/plugins/upload_engine/public/javascripts
      create  vendor/plugins/upload_engine/public/javascripts/upload_engine.js
      create  vendor/plugins/upload_engine/public/stylesheets
      create  vendor/plugins/upload_engine/public/stylesheets/upload_engine.css
      create  vendor/plugins/upload_engine/tasks
      create  vendor/plugins/upload_engine/tasks/upload_engine.rake
      create  vendor/plugins/upload_engine/test
      create  vendor/plugins/upload_engine/test/test_helper.rb
      create  vendor/plugins/upload_engine/test/fixtures
      create  vendor/plugins/upload_engine/test/functional
      create  vendor/plugins/upload_engine/test/unit

$ mv app/models/upload.rb vendor/plugins/upload_engine/app/models
$ mv app/controllers/upload_controller.rb vendor/plugins/upload_engine/app/controllers
$ mv app/views/upload vendor/plugins/upload_engine/app/views
$ mv public/javascripts/upload_engine.js vendor/plugins/upload_engine/public/javascripts
$ mv public/stylesheets/upload_engine.css vendor/plugins/upload_engine/public/stylesheets

Engines.start :upload_engine
$ script/server

This is way cool. Great work, Jon !

Seems there’s a problem with the Rails generator. I was receiving an odd (pun intended) error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ ruby script\generate migration -tc AddGamesAndCategories1
odd number of arguments for Hash
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../options.rb:130:in `[]'
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../options.rb:130:in `add_general_options!'
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../options.rb:130:in `call'
  C:/ruby/lib/ruby/1.8/optparse.rb:1308:in `order!'
  C:/ruby/lib/ruby/1.8/optparse.rb:1266:in `catch'
  C:/ruby/lib/ruby/1.8/optparse.rb:1266:in `order!'
  C:/ruby/lib/ruby/1.8/optparse.rb:1346:in `permute!'
  C:/ruby/lib/ruby/1.8/optparse.rb:1373:in `parse!'
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../options.rb:89:in `parse!'
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../options.rb:85:in `initialize'
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../options.rb:85:in `new'
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../options.rb:85:in `parse!'
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../scripts.rb:19:in `run'
  ./script/../config/../vendor/rails/railties/lib/commands/generate.rb:6
  C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__'
  C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
  script/generate:3
After a bit of debugging, it turned out that there’s a small problem with the Rails::Generator::Options::ClassMethods#add_general_options! method.
1
2
3
4
5
6
opt.on('-c', '--svn',
  'Modify files with subversion. (Note: svn must be in path)') {
  options[:svn] =
    Hash[*`svn status`.collect { |e|
      e.chop.split.reverse unless
        e.chop.split.size != 2 }.flatten] }
(reformatted for visibility)

This line will return nil, unless the line splits in two (A app/models/test.rb). The problem is that if the number of lines that don’t split in two is odd, then the flattened array will contain an odd number of items, which will cause Hash.new to fail.

The solution ? compact the array before flattening. I already submitted ticket #2814 with a patch.

In the meantime, I’m running a patched copy of Rails.

UPDATE: revision 2972 applied a modified version of my original patch.

 

Search

A picture of me

I am François Beausoleil, a Ruby on Rails coder. During the day, I work on XLsuite. At night, I am interested many things. Read my biography

Tags

(3) (1) (0) (2) (1) (1) (2) (2) (1) (2) (1) (2) (1) (2) (1) (1) (1) (1) (2) (14) (1) (1) (1) (1) (2) (1) (1) (2) (0) (1) (2) (1) (3) (1) (1) (1) (1) (1) (1) (0) (3) (2) (1) (2) (2) (1) (3) (2) (8) (8) (9) (12) (1) (1) (3) (1) (1) (1) (1) (1) (1) (2) (2) (2) (1) (1) (3) (1) (3) (1) (0) (23) (1) (1) (0) (1) (1) (1) (23) (25) (1) (1) (13) (1) (1) (2) (3) (1) (1) (4) (1) (2) (3) (0) (1) (7) (3) (1) (5) (5) (2) (2) (2) (4) (6) (7) (1) (0) (1) (1) (2) (2) (1) (4) (12) (2) (1) (2) (4) (1) (1) (1) (2) (8) (2) (3) (2) (2) (1) (3) (1) (1)

Links

Projects I work on

Categories

Archives