class LolDba::CLI

Public Class Methods

new(path, options) click to toggle source
# File lib/lol_dba/cli.rb, line 27
def initialize(path, options)
  @path = path
  @options = options
end
parse_options() click to toggle source
# File lib/lol_dba/cli.rb, line 11
def parse_options
  options = {}
  OptionParser.new do |opts|
    opts.on('-d', '--debug',
            'Show stack traces when an error occurs.') do |opt|
      options[:debug] = opt
    end
    opts.on_tail('-v', '--version', 'Show version') do
      puts LolDba::VERSION
      exit
    end
  end.parse!
  options
end
start() click to toggle source
# File lib/lol_dba/cli.rb, line 7
def start
  new(Dir.pwd, parse_options).start(ARGV.first)
end

Public Instance Methods

start(arg) click to toggle source
# File lib/lol_dba/cli.rb, line 32
def start(arg)
  load_application
  select_action(arg)
rescue SystemExit
  raise $!
rescue Exception => exception
  if @options[:debug]
    warn "Failed: #{exception.class}: #{exception.message}"
    warn exception.backtrace.map { |trace| "    from #{trace}" }
  end
end

Protected Instance Methods

load_application() click to toggle source

Tks to github.com/voormedia/rails-erd/blob/master/lib/rails_erd/cli.rb

# File lib/lol_dba/cli.rb, line 59
def load_application
  require "#{@path}/config/environment"
end
select_action(arg) click to toggle source
# File lib/lol_dba/cli.rb, line 46
def select_action(arg)
  if arg =~ /db:find_indexes/
    success = LolDba::IndexFinder.run
    exit(1) if success
  elsif arg !~ /\[/
    LolDba::SqlGenerator.run('all')
  else
    which = arg.match(/.*\[(.*)\].*/).captures[0]
    LolDba::SqlGenerator.run(which)
  end
end