1. Skip to navigation
  2. Skip to content

The ELC Community Blog

A knowledge exchange on Ruby on Rails and Agile Development


Environment Scripts in merb

by josh on January 22, 2008

The time has come to run a script using cron or another background worker and I find myself reaching for script/runner only...

It's not there!

No worries...here's what you do:

#!/usr/bin/env ruby
require 'rubygems'
require 'merb'
require File.dirname(__FILE__) + '/../config/dependencies'
load_paths = []
load_paths.unshift(File.join(Merb.root , '/app/models'))
# add more load paths here, such as
# load_paths.unshift(File.join(Merb.root , '/app/controllers'))
load_paths.each do |path|
  Dir.glob("#{path}/*").each { |m| require m }
end

You can avoid everything from line 4 onward by using Merb::BootLoader.load_application but it will load the routes, which takes longer.

Check in your merb gem (lib/merb/boot_loader.rb) for more help.

Also posted to fr.ivolo.us

Comments

Add a comment


home | services | Ruby on Rails Development | code | blog | company