public
Fork of drnic/ruby-on-rails-tmbundle
Description: Ruby on Rails TextMate bundle [master branch is svn trunk; patches to drnicwilliams@gmail.com]
Homepage: http://macromates.com
Clone URL: git://github.com/Infininight/ruby-on-rails-tmbundle.git
ruby-on-rails-tmbundle / Commands / Show DB Schema.tmCommand
100644 53 lines (45 sloc) 1.74 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?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>command</key>
  <string>#!/usr/bin/env ruby
 
require "#{ENV['TM_SUPPORT_PATH']}/lib/progress"
TextMate.call_with_progress(:title =&gt; "Contacting SQL Server", :message =&gt; "Fetching database schema…") do
 
  project = ENV['TM_PROJECT_DIRECTORY']
  word = ENV['TM_CURRENT_WORD']
 
  require "#{project}/config/boot"
  require "#{project}/config/environment"
 
  klass = Object.const_get(word) rescue nil
  if klass and klass.class == Class and klass.ancestors.include?(ActiveRecord::Base)
    columns = klass.columns_hash
 
    data = []
    data += [%w[column primary sql_type default]]
    data += [%w[------ ------- -------- -------]]
    data += columns.collect { |col, attrs| [col, attrs.primary.to_s, attrs.sql_type.to_s, attrs.default.to_s] }
 
    STDOUT &lt;&lt; data.inject('') do |output, array|
      output + array.inject('') { |row_str, value| row_str + value.ljust(20) } + "\n"
    end
  elsif klass and klass.class == Class and not klass.ancestors.include?(ActiveRecord::Base)
    STDOUT &lt;&lt; "#{word} is not an Active Record derived class"
  else
    STDOUT &lt;&lt; "#{word} was not recognised as a class"
  end
 
end
</string>
  <key>input</key>
  <string>none</string>
  <key>keyEquivalent</key>
  <string>^@S</string>
  <key>name</key>
  <string>Show DB Schema for Current Class</string>
  <key>output</key>
  <string>showAsTooltip</string>
  <key>scope</key>
  <string>source.ruby.rails</string>
  <key>uuid</key>
  <string>1970AE74-3949-40B3-B263-727AA3FF167A</string>
</dict>
</plist>