Class: ActiveRecord::SqlAnalyzer::CLI
- Inherits:
-
Object
- Object
- ActiveRecord::SqlAnalyzer::CLI
- Defined in:
- lib/active_record/sql_analyzer/cli.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#processor ⇒ Object
readonly
Returns the value of attribute processor.
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #parse_options(args) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
6 7 8 9 10 |
# File 'lib/active_record/sql_analyzer/cli.rb', line 6 def initialize @options = { concurrency: 6 } end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/active_record/sql_analyzer/cli.rb', line 4 def @options end |
#processor ⇒ Object (readonly)
Returns the value of attribute processor.
4 5 6 |
# File 'lib/active_record/sql_analyzer/cli.rb', line 4 def processor @processor end |
Instance Method Details
#parse_options(args) ⇒ Object
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 |
# File 'lib/active_record/sql_analyzer/cli.rb', line 38 def (args) opts = OptionParser.new opts.on("--log-dir [DIR]", String, "Directory that logs are in") do |val| unless Dir.exist?(val) raise ArgumentError, "log directory '#{val}' does not exist" end [:log_dir] = val end opts.on("--dest-dir [DIR]", String, "Directory to dump logs to") do |val| unless Dir.exist?(val) raise ArgumentError, "dest directory '#{val}' does not exist" end [:dest_dir] = val end opts.on("-c", "--concurrency", Integer, "How many threads to use for processing log files") do |val| if val <= 0 raise ArgumentError, "Concurrency must be >0" end [:concurrency] = val end opts.on_tail("-h", "--help") do puts opts exit end opts.parse(args) end |
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/active_record/sql_analyzer/cli.rb', line 16 def run definition_logs = Dir["#{[:log_dir]}/*_definitions.log*"].map do |path| [File.basename(path).gsub(/_definitions\.log.*/, ""), path] end if definition_logs.empty? raise ArgumentError, "Cannot find any log files in '#{[:log_dir]}'" end # Process the definition logs processor.run_definition(definition_logs) # Process the usage logs usage_logs = Dir["#{[:log_dir]}/{#{definition_logs.map(&:first).uniq.join(",")}}.log*"].map do |path| [File.basename(path).split(".", 2).first, path] end processor.run_usage(usage_logs) processor.dump([:dest_dir]) end |