Skip to content

Commit

Permalink
Move codes shared with Analyzer and Extractor to the module
Browse files Browse the repository at this point in the history
  • Loading branch information
Haruka Yoshihara committed Dec 18, 2012
1 parent 34df7e7 commit 74033bc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
15 changes: 3 additions & 12 deletions lib/groonga/query-log/analyzer.rb
Expand Up @@ -19,13 +19,16 @@

require "optparse"
require "json"
require "groonga/query-log/commandline-utils"
require "groonga/query-log/parser"
require "groonga/query-log/analyzer/streamer"
require "groonga/query-log/analyzer/sized-statistics"

module Groonga
module QueryLog
class Analyzer
include CommandLineUtils

class Error < StandardError
end

Expand Down Expand Up @@ -214,18 +217,6 @@ def create_stream_reporter
Groonga::QueryLog::StreamConsoleQueryLogReporter.new
end
end

def log_via_stdin?
input_with_pipe? or input_with_redirect?
end

def input_with_pipe?
File.pipe?($stdin)
end

def input_with_redirect?
not File.select([$stdin], [], [], 0).nil?
end
end
end
end
35 changes: 35 additions & 0 deletions lib/groonga/query-log/commandline-utils.rb
@@ -0,0 +1,35 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

module Groonga
module QueryLog
module CommandLineUtils
def log_via_stdin?
input_with_pipe? or input_with_redirect?
end

def input_with_pipe?
File.pipe?($stdin)
end

def input_with_redirect?
not File.select([$stdin], [], [], 0).nil?
end
end
end
end
14 changes: 2 additions & 12 deletions lib/groonga/query-log/extractor.rb
Expand Up @@ -20,11 +20,13 @@
require "ostruct"
require "optparse"
require "pathname"
require "groonga/query-log/commandline-utils"
require "groonga/query-log/parser"

module Groonga
module QueryLog
class Extractor
include CommandLineUtils

class Error < StandardError
end
Expand Down Expand Up @@ -166,18 +168,6 @@ def target?(command)

true
end

def log_via_stdin?
input_with_pipe? or input_with_redirect?
end

def input_with_pipe?
File.pipe?($stdin)
end

def input_with_redirect?
not File.select([$stdin], [], [], 0).nil?
end
end
end
end

0 comments on commit 74033bc

Please sign in to comment.