<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>beforeRunningCommand</key>
	<string>nop</string>
	<key>bundleUUID</key>
	<string>467B298F-6227-11D9-BFB1-000D93589AF6</string>
	<key>command</key>
	<string># just to remind you of some useful environment variables
# see Help / Environment Variables for the full list

base_files=($(${TM_RUBY:=ruby} &lt;&lt;"EOF"
module_name = nil

def find_module_name_in_file(file_name)
  File.open(file_name) do |file|
    n = ENV['TM_LINE_NUMBER'].to_i
    lines     = file.read.split("\n")[0...n]
    lines.each do |line| 
      match_data = line.match(/^module\b(.*)\b/)
	 return match_data[1].strip if match_data
    end
  end
  nil
end

def file_names_that_include_module(module_name)
  file_names = []
  Dir.new(".").each do |file|
    unless File.directory?(file)
      match_data = nil
      File.open(file) do |f|
        match_data = f.read.match(/.*include\s+#{module_name}\s.*/)
      end
      if match_data
        file_names &lt;&lt; file 
      end
    end
  end
  file_names
end 

def bottom_level_includers(file_name)
  bottom_levels = []

  module_name = find_module_name_in_file(file_name)
  if module_name.nil? 
    bottom_levels &lt;&lt; file_name 
  else
    file_names = file_names_that_include_module(module_name)
    file_names.each do |f_name|
      bottom_levels += bottom_level_includers(f_name)
    end
  end 
  bottom_levels 
end

module_name = find_module_name_in_file(ENV['TM_FILEPATH'])
file_names = file_names_that_include_module(module_name)
bottom_level_includers = []


file_names.each do |file_name|
 bottom_level_includers += bottom_level_includers(file_name)
end

print bottom_level_includers.join(" ")

EOF))

export RUBYLIB="$TM_BUNDLE_SUPPORT/RubyMate${RUBYLIB:+:$RUBYLIB}"
for file_name in ${base_files[@]}
do
 "${TM_RUBY:-ruby}" -e '
require "#{ENV["TM_SUPPORT_PATH"]}/lib/scriptmate"
require "cgi"

$SCRIPTMATE_VERSION = "$Revision: 6354 $"

class UserScript
  def initialize(content, write_content_to_stdin=true)
    file_name = File.join(ENV["TM_DIRECTORY"], "'$file_name'")
    @write_content_to_stdin = write_content_to_stdin
    @content = content
    #match the entire she-bang.
    @hashbang = $1 if @content =~ /\A#!(.*)$/
    if ENV.has_key? "TM_FILEPATH" then
      @path = file_name 
      @display_name = File.basename(@path)
      # save file
      #open(@path, "w") { |io| io.write @content }
    else
      @path = "-"
      @display_name = "untitled"
    end
  end
end

require "run_script"
'

done
</string>
	<key>input</key>
	<string>none</string>
	<key>keyEquivalent</key>
	<string>@m</string>
	<key>name</key>
	<string>run_all_unit_tests_in_module</string>
	<key>output</key>
	<string>showAsHTML</string>
	<key>uuid</key>
	<string>F642D39A-E1D4-49CE-B526-DAF6A5AB913E</string>
</dict>
</plist>
