Last active
December 19, 2015 04:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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