I’m spending a fair amount of my time working on non-Rails Ruby projects lately and I’ve been missing the fine code generation toys in Rails. So tonight, for the fun of it and because I was hankering to play with cucumber, I hacked up the minimal set of bits that gets you script/generate in your non-Rails project.

This is how we do it:

> mkdir my_non_rails_proj> cd my_non_rails_proj> mkdir script config> touch config/environment.rb> cat > config/boot.rbRAILS_ROOT = "#{File.dirname( __FILE__ )}/.." unless defined?(RAILS_ROOT)RAILS_ENV = nilrequire 'rubygems'require 'initializer'Rails.configuration = Rails::Configuration.new^D> cp -p /path/to/gems/rails-2.3.2/bin/generate script/.> ./script/generateUsage: ./script/generate generator [options] [args]Rails Info: -v, --version Show the Rails version number and quit. -h, --help Show this help message and quit.[...]> ./script/generate cucumber create features/step_definitions create features/step_definitions/webrat_steps.rb create features/support create features/support/env.rb create features/support/paths.rb create lib/tasks create lib/tasks/cucumber.rake create script/cucumber> touch Rakefile> rake features[... large lack of FAIL ...]>

Voila! Not guaranteed to work for all Rails generators, but it bootstrapped rspec and cucumber just fine, which was the point of my exercise. Someday I’ll make a generator:bootstrap rake task or gem something if I need to do it again.



blog comments powered by Disqus

Published

03 June 2009

Categories

hacking ruby/rails