[Groonga-commit] groonga/groonga-query-log at be48d65 [master] Indent

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Aug 12 18:37:28 JST 2015


Kouhei Sutou	2015-08-12 18:37:28 +0900 (Wed, 12 Aug 2015)

  New Revision: be48d65b53ee9f15d573093fc600159f5be5b342
  https://github.com/groonga/groonga-query-log/commit/be48d65b53ee9f15d573093fc600159f5be5b342

  Message:
    Indent

  Modified files:
    lib/groonga/query-log/command/extract.rb

  Modified: lib/groonga/query-log/command/extract.rb (+131 -131)
===================================================================
--- lib/groonga/query-log/command/extract.rb    2015-08-12 18:37:13 +0900 (873d451)
+++ lib/groonga/query-log/command/extract.rb    2015-08-12 18:37:28 +0900 (acab826)
@@ -26,167 +26,167 @@ require "groonga/query-log/command-line-utils"
 module Groonga
   module QueryLog
     module Command
-    class Extract
-      include CommandLineUtils
+      class Extract
+        include CommandLineUtils
 
-      class Error < StandardError
-      end
-
-      attr_accessor :options
-      attr_reader :option_parser
+        class Error < StandardError
+        end
 
-      def initialize
-        @options = nil
-        @option_parser = nil
-        setup_options
-      end
+        attr_accessor :options
+        attr_reader :option_parser
 
-      # Executes extractor for groonga's query logs.
-      # "groonga-query-log-extract" command runs this method.
-      #
-      # @example
-      #   extractor = Groonga::QueryLog::Command::Extract.new
-      #   extractor.run("--output", "commands.output",
-      #                 "--command", "select",
-      #                 "query.log")
-      #
-      # If only paths of query log files are specified,
-      # this method prints command(s) of them to console.
-      #
-      # @param [Array<String>] arguments arguments for
-      #   groonga-query-log-extract. Please execute
-      #   "groonga-query-log-extract --help" or see #setup_options.
-      def run(arguments)
-        begin
-          log_paths = @option_parser.parse!(arguments)
-        rescue OptionParser::ParseError
-          $stderr.puts($!.message)
-          return false
+        def initialize
+          @options = nil
+          @option_parser = nil
+          setup_options
         end
 
-        if log_paths.empty?
-          unless log_via_stdin?
-            $stderr.puts("Error: Please specify input log files.")
+        # Executes extractor for groonga's query logs.
+        # "groonga-query-log-extract" command runs this method.
+        #
+        # @example
+        #   extractor = Groonga::QueryLog::Command::Extract.new
+        #   extractor.run("--output", "commands.output",
+        #                 "--command", "select",
+        #                 "query.log")
+        #
+        # If only paths of query log files are specified,
+        # this method prints command(s) of them to console.
+        #
+        # @param [Array<String>] arguments arguments for
+        #   groonga-query-log-extract. Please execute
+        #   "groonga-query-log-extract --help" or see #setup_options.
+        def run(arguments)
+          begin
+            log_paths = @option_parser.parse!(arguments)
+          rescue OptionParser::ParseError
+            $stderr.puts($!.message)
             return false
           end
-          log = $stdin
-        else
-          log = log_paths
-        end
 
-        if****@optio*****_path
-          File.open(@options.output_path, "w") do |output|
-            extract(log, output)
+          if log_paths.empty?
+            unless log_via_stdin?
+              $stderr.puts("Error: Please specify input log files.")
+              return false
+            end
+            log = $stdin
+          else
+            log = log_paths
           end
-        else
-          extract(log, $stdout)
-        end
 
-        true
-      end
-
-      private
-      def setup_options
-        @options = OpenStruct.new
-        @options.unify_format = nil
-        @options.commands = []
-        @options.exclude_commands = []
-        @options.output_path = nil
-        @option_parser = OptionParser.new do |parser|
-          parser.version = VERSION
-          parser.banner += " QUERY_LOG1 ..."
-
-          available_formats = ["uri", "command"]
-          parser.on("--unify-format=FORMAT",
-                    available_formats,
-                    "Unify command format to FORMAT.",
-                    "(#{available_formats.join(', ')})",
-                    "[not unify]") do |format|
-            @options.unify_format = format
+          if****@optio*****_path
+            File.open(@options.output_path, "w") do |output|
+              extract(log, output)
+            end
+          else
+            extract(log, $stdout)
           end
 
-          parser.on("--command=COMMAND",
-                    "Extract only COMMAND.",
-                    "To extract one or more commands,",
-                    "specify this command a number of times.",
-                    "Use /.../ as COMMAND to match command with regular expression.",
-                    "[all commands]") do |command|
-            case command
-            when /\A\/(.*)\/(i)?\z/
-              @options.commands << Regexp.new($1, $2 == "i")
-            when
-              @options.commands << command
+          true
+        end
+
+        private
+        def setup_options
+          @options = OpenStruct.new
+          @options.unify_format = nil
+          @options.commands = []
+          @options.exclude_commands = []
+          @options.output_path = nil
+          @option_parser = OptionParser.new do |parser|
+            parser.version = VERSION
+            parser.banner += " QUERY_LOG1 ..."
+
+            available_formats = ["uri", "command"]
+            parser.on("--unify-format=FORMAT",
+                      available_formats,
+                      "Unify command format to FORMAT.",
+                      "(#{available_formats.join(', ')})",
+                      "[not unify]") do |format|
+              @options.unify_format = format
             end
-          end
 
-          parser.on("--exclude-command=COMMAND",
-                    "Don't extract COMMAND.",
-                    "To ignore one or more commands,",
-                    "specify this command a number of times.",
-                    "Use /.../ as COMMAND to match command with regular expression.",
-                    "[no commands]") do |command|
-            case command
-            when /\A\/(.*)\/(i)?\z/
-              @options.exclude_commands << Regexp.new($1, $2 == "i")
-            when
-              @options.exclude_commands << command
+            parser.on("--command=COMMAND",
+                      "Extract only COMMAND.",
+                      "To extract one or more commands,",
+                      "specify this command a number of times.",
+                      "Use /.../ as COMMAND to match command with regular expression.",
+                      "[all commands]") do |command|
+              case command
+              when /\A\/(.*)\/(i)?\z/
+                @options.commands << Regexp.new($1, $2 == "i")
+              when
+                @options.commands << command
+              end
             end
-          end
 
-          parser.on("--output=PATH",
-                    "Output to PATH.",
-                    "[standard output]") do |path|
-            @options.output_path = path
+            parser.on("--exclude-command=COMMAND",
+                      "Don't extract COMMAND.",
+                      "To ignore one or more commands,",
+                      "specify this command a number of times.",
+                      "Use /.../ as COMMAND to match command with regular expression.",
+                      "[no commands]") do |command|
+              case command
+              when /\A\/(.*)\/(i)?\z/
+                @options.exclude_commands << Regexp.new($1, $2 == "i")
+              when
+                @options.exclude_commands << command
+              end
+            end
+
+            parser.on("--output=PATH",
+                      "Output to PATH.",
+                      "[standard output]") do |path|
+              @options.output_path = path
+            end
           end
         end
-      end
 
-      def extract(log, output)
-        if log.instance_of?(Array)
-          log.each do |log_path|
-            File.open(log_path) do |log_file|
-              extract_command(log_file, output)
+        def extract(log, output)
+          if log.instance_of?(Array)
+            log.each do |log_path|
+              File.open(log_path) do |log_file|
+                extract_command(log_file, output)
+              end
             end
+          else
+            extract_command(log, output)
           end
-        else
-          extract_command(log, output)
         end
-      end
 
-      def extract_command(log, output)
-        parser = Groonga::QueryLog::Parser.new
-        parser.parse(log) do |statistic|
-          command = statistic.command
-          next unless target?(command)
-          command_text = nil
-          case****@optio*****_format
-          when "uri"
-            command_text = command.to_uri_format
-          when "command"
-            command_text = command.to_command_format
-          else
-            command_text = statistic.raw_command
+        def extract_command(log, output)
+          parser = Groonga::QueryLog::Parser.new
+          parser.parse(log) do |statistic|
+            command = statistic.command
+            next unless target?(command)
+            command_text = nil
+            case****@optio*****_format
+            when "uri"
+              command_text = command.to_uri_format
+            when "command"
+              command_text = command.to_command_format
+            else
+              command_text = statistic.raw_command
+            end
+            output.puts(command_text)
           end
-          output.puts(command_text)
         end
-      end
 
-      def target?(command)
-        name = command.name
-        target_commands =****@optio*****
-        exclude_commands =****@optio*****_commands
+        def target?(command)
+          name = command.name
+          target_commands =****@optio*****
+          exclude_commands =****@optio*****_commands
 
-        unless target_commands.empty?
-          return target_commands.any? {|target_command| target_command === name}
-        end
+          unless target_commands.empty?
+            return target_commands.any? {|target_command| target_command === name}
+          end
 
-        unless exclude_commands.empty?
-          return (not exclude_commands.any? {|exclude_command| exclude_command === name})
-        end
+          unless exclude_commands.empty?
+            return (not exclude_commands.any? {|exclude_command| exclude_command === name})
+          end
 
-        true
+          true
+        end
       end
     end
-    end
   end
 end
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index