class Thor::Runner

def install(name)

def install(name)
  initialize_thorfiles
  begin
    contents = open(name).read
  rescue OpenURI::HTTPError
    raise Error, "Error opening URI `#{name}'"
  rescue Errno::ENOENT
    raise Error, "Error opening file `#{name}'"
  end
  
  is_uri = File.exist?(name) ? false : true
  
  puts "Your Thorfile contains: "
  puts contents
  print "Do you wish to continue [y/N]? "
  response = Readline.readline
  
  return false unless response =~ /^\s*y/i
  
  constants = Thor::Util.constants_in_contents(contents)
  
  # name = name =~ /\.thor$/ || is_uri ? name : "#{name}.thor"
  
  as = options["as"] || begin
    first_line = contents.split("\n")[0]
    (match = first_line.match(/\s*#\s*module:\s*([^\n]*)/)) ? match[1].strip : nil
  end
      
  if !as
    print "Please specify a name for #{name} in the system repository [#{name}]: "
    as = Readline.readline
    as = name if as.empty?
  end
  
  FileUtils.mkdir_p thor_root
  
  yaml_file = File.join(thor_root, "thor.yml")
  FileUtils.touch(yaml_file)
  yaml = thor_yaml
  
  location = (options[:relative] || is_uri) ? name : File.expand_path(name)
  yaml[as] = {:filename => Digest::MD5.hexdigest(name + as), :location => location, :constants => constants}
  
  save_yaml(yaml)
  
  puts "Storing thor file in your system repository"
  
  File.open(File.join(thor_root, yaml[as][:filename]), "w") do |file|
    file.puts contents
  end
  
  yaml[as][:filename] # Indicate sucess
end