Created
August 25, 2020 01:09
-
-
Save bluerabbit/451b974be2f762bb6301b8091e21812d to your computer and use it in GitHub Desktop.
rubyファイルの中にあるSQL文字列を抜き取る
This file contains hidden or 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
# ruby extract_sql.rb app.rb | |
require 'ripper' | |
$SQL_TEXTS = [] | |
class ExtractSql < Ripper::Filter | |
def on_tstring_content(tok, _) | |
text = tok.strip.upcase | |
$SQL_TEXTS << text if text.index('SELECT') || text.index('UPDATE') || text.index('INSERT') || text.index('DELETE') | |
end | |
end | |
ExtractSql.new(File.read(ARGV[0])).parse('') | |
puts $SQL_TEXTS.sort |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment