Latest Tweets:
This is a tumbling log of things and thoughts that pass my way.
If you got here by accident, you may want to visit my website instead.
the output from Rails’ script/runner -h says you can create custom scripts with a fancy shebang line:You can also use runner as a shebang line for your scripts like this: ------------------------------------------------------------- #!/usr/bin/env /Users/bob/Projects/glowworm/script/runner Product.find(:all).each { |p| p.price *= 2 ; p.save! } -------------------------------------------------------------but I hate the idea of hardcoding a path like that. Here’s a workaround: open up your new script, something like script/my_custom_script and fill it like so#!/usr/bin/env ruby unless $0 =~ /runner/ system("#{File.dirname(__FILE__)}/runner", __FILE__) exit 0 end puts 'your code goes here'
Nice idea! Here’s my take on it:
#!/usr/bin/env ruby
exec(File.join(File.dirname($0), "..", "runner"), __FILE__) unless File.basename($0) == 'runner'
puts 'your code goes here'