Class: Piggly::Command::Untrace

Inherits:
Base show all
Defined in:
lib/piggly/command/untrace.rb

Class Method Summary collapse

Methods inherited from Base

command, connect, filter, o_accumulate, o_cache_root, o_connection_name, o_database_yml, o_dry_run, o_include_paths, o_reject, o_report_root, o_select, o_version

Class Method Details

.configure(argv, config = Config.new) ⇒ Object

Parses command-line options



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/piggly/command/untrace.rb', line 50

def configure(argv, config = Config.new)
  p = OptionParser.new do |o|
    o.on("-t", "--dry-run",         "only print the names of matching procedures", &o_dry_run(config))
    o.on("-s", "--select PATTERN",  "select procedures matching PATTERN", &o_select(config))
    o.on("-r", "--reject PATTERN",  "ignore procedures matching PATTERN", &o_reject(config))
    o.on("-c", "--cache-root PATH", "local cache directory", &o_cache_root(config))
    o.on("-d", "--database PATH",   "read 'piggly' database adapter settings from YAML file", &o_database_yml(config))
    o.on("-k", "--connection NAME", "use connection adapter NAME", &o_connection_name(config))
    o.on("-V", "--version",         "show version", &o_version(config))
    o.on("-h", "--help",            "show this message") { abort o.to_s }
  end

  begin
    p.parse! argv
    config
  rescue OptionParser::InvalidOption,
         OptionParser::InvalidArgument,
         OptionParser::MissingArgument
    puts p
    puts
    puts $!
    exit! 1
  end
end

.find_procedures(filters, index) ⇒ Object

Returns a list of Procedure values that satisfy at least one of the given filters



39
40
41
42
43
44
45
# File 'lib/piggly/command/untrace.rb', line 39

def find_procedures(filters, index)
  if filters.empty?
    index.procedures
  else
    filters.inject(Set.new){|set, filter| set | index.procedures.select(&filter) }
  end
end

.main(argv) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/piggly/command/untrace.rb', line 8

def main(argv)
  config      = configure(argv)
  index       = Dumper::Index.new(config)
  connection  = connect(config)
  procedures  = filter(config, index)

  if procedures.empty?
    if config.filters.empty?
      abort "no stored procedures in the cache"
    else
      abort "no stored procedures in the cache matched your criteria"
    end
  elsif config.dry_run?
    puts procedures.map{|x| x.signature }
    exit 0
  end

  untrace(Installer.new(config, connection), procedures)
end

.untrace(installer, procedures) ⇒ Object

Restores database procedures from file cache



31
32
33
34
# File 'lib/piggly/command/untrace.rb', line 31

def untrace(installer, procedures)
  puts "restoring #{procedures.size} procedures"
  installer.uninstall(procedures)
end