Class: Oink::Cli
- Inherits:
-
Object
- Object
- Oink::Cli
- Defined in:
- lib/oink/cli.rb
Instance Method Summary collapse
-
#initialize(args) ⇒ Cli
constructor
A new instance of Cli.
- #process ⇒ Object
Constructor Details
#initialize(args) ⇒ Cli
Returns a new instance of Cli.
9 10 11 |
# File 'lib/oink/cli.rb', line 9 def initialize(args) @args = args end |
Instance Method Details
#process ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/oink/cli.rb', line 13 def process = { :format => :short_summary, :type => :memory } op = OptionParser.new do |opts| opts. = "Usage: oink [options] files" opts.on("-t", "--threshold [INTEGER]", Integer, "Memory threshold in MB") do |threshold| [:threshold] = threshold end opts.on("-f", "--file filepath", "Output to file") do |filename| [:output_file] = filename end format_list = (Oink::Reports::Base::FORMAT_ALIASES.keys + Oink::Reports::Base::FORMATS).join(',') opts.on("--format FORMAT", Oink::Reports::Base::FORMATS, Oink::Reports::Base::FORMAT_ALIASES, "Select format", " (#{format_list})") do |format| [:format] = format.to_sym end opts.on("-m", "--memory", "Check for Memory Threshold (default)") do |v| [:type] = :memory end opts.on("-r", "--active-record", "Check for Active Record Threshold") do |v| [:type] = :active_record end end op.parse!(@args) if @args.empty? puts op exit end output = nil if [:output_file] output = File.open([:output_file], 'w') else output = STDOUT end files = get_file_listing(@args) handles = files.map { |f| File.open(f) } if [:type] == :memory [:threshold] ||= 75 [:threshold] *= 1024 Oink::Reports::MemoryUsageReport.new(handles, [:threshold], :format => [:format]).print(output) elsif [:type] == :active_record [:threshold] ||= 500 Oink::Reports::ActiveRecordInstantiationReport.new(handles, [:threshold], :format => [:format]).print(output) end output.close handles.each { |h| h.close } end |