Skip to content

Instantly share code, notes, and snippets.

@luikore
Last active December 19, 2015 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luikore/5899132 to your computer and use it in GitHub Desktop.
Save luikore/5899132 to your computer and use it in GitHub Desktop.
A textmate command to show model fields so model can be cleaner without annotates
#!/usr/bin/env ruby
name = File.basename ENV['TM_FILENAME']
name = name.dup
name[/\.rb$/] = ''
names = []
File.read(File.join(ENV['TM_PROJECT_DIRECTORY'], 'db/schema.rb')).scan(/( create_table "(\w+).*? end)/m) do |s, n|
names << [n.size, s] if n.start_with?(name)
end
puts names.min_by(&:first).last
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment