Skip to content

Instantly share code, notes, and snippets.

@bluerabbit
Created August 25, 2020 01:09
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 bluerabbit/451b974be2f762bb6301b8091e21812d to your computer and use it in GitHub Desktop.
Save bluerabbit/451b974be2f762bb6301b8091e21812d to your computer and use it in GitHub Desktop.
rubyファイルの中にあるSQL文字列を抜き取る
# 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