#!/usr/bin/env ruby require 'rubygems' require 'fileutils' require 'tempfile' require 'optparse' require 'prompter' require 'dye' version = File.read(File.expand_path('../../VERSION', __FILE__)).strip copy = Dye.dye "irt #{version} (c) 2010-2011 Domizio Demichelis", :blue, :bold options = {} optparse = OptionParser.new do |opts| opts.banner = < '[ 'y' options[:interactive_eof] = true dirname = File.dirname(path) FileUtils.mkdir_p(dirname) unless File.directory?(dirname) File.open(path, 'w') {|f| f.puts "\n" } # one empty line makes irb of 1.9.2 happy end File.directory?(path) ? Dir.glob(File.join(path, '**/*.irt')) : path end.flatten if files.empty? Prompter.say_notice 'No *.irt files to run' exit end cmd_format = if File.exists?('./config/environment.rb') if File.exists?('./script/rails') 'rails c %s %s %s' elsif File.exists?('./script/console') 'ruby script/console --irb="irt_rails2 %s"' end else 'irt_irb %s %s' end if cmd_format.match(/^ruby script\/console/) ENV['RAILS_ENV'] ||= options[:rails_env] end ENV['IRT_INTERACTIVE_EOF'] = options[:interactive_eof].inspect if options[:interactive_eof] files.each do |file| ENV['IRT_COMMAND'] = sprintf cmd_format, file, options[:irb_options], options[:rails_env] unless system(ENV['IRT_COMMAND']) puts "\e[0m" if Dye.color? exit(1) end end