Haruka Yoshihara
null+****@clear*****
Fri Dec 14 18:13:40 JST 2012
Haruka Yoshihara 2012-12-14 18:13:40 +0900 (Fri, 14 Dec 2012) New Revision: ec8ab08994c9ed12642c77da25a111a3ba4b5fd9 https://github.com/groonga/groonga-query-log/commit/ec8ab08994c9ed12642c77da25a111a3ba4b5fd9 Log: extractor: implement #target? from bin/groonga-query-log-extract Added files: test/test-extractor.rb Modified files: lib/groonga/query-log/extractor.rb Modified: lib/groonga/query-log/extractor.rb (+12 -0) =================================================================== --- lib/groonga/query-log/extractor.rb 2012-12-14 17:55:32 +0900 (1b9d5a2) +++ lib/groonga/query-log/extractor.rb 2012-12-14 18:13:40 +0900 (bce755c) @@ -41,6 +41,18 @@ module Groonga setup_options end + private + def target?(command) + name = command.name + if****@optio*****? {|target_command| target_command === name} + true + elsif****@optio*****_commands.any? {|exclude_command| exclude_command == name} + false + else + true + end + end + def setup_options @options = OpenStruct.new @options.unify_format = nil Added: test/test-extractor.rb (+52 -0) 100755 =================================================================== --- /dev/null +++ test/test-extractor.rb 2012-12-14 18:13:40 +0900 (05387b2) @@ -0,0 +1,52 @@ +#!/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 + +require "groonga/query-log/extractor" +require "groonga/command" + +class TestExtractor < Test::Unit::TestCase + def setup + @extractor = Groonga::QueryLog::Extractor.new + end + + class TestTarget < self + def test_include + @extractor.options.commands = ["register"] + assert_true(target?("register")) + assert_false(target?("dump")) + end + + def test_exclude + @extractor.options.exclude_commands = ["dump"] + assert_true(target?("register")) + assert_false(target?("dump")) + end + + def test_not_specified + assert_true(target?("register")) + assert_true(target?("dump")) + end + + private + def target?(name) + command_class = Groonga::Command.find(name) + command = command_class.new(name, []) + @extractor.send(:target?, command) + end + end +end -------------- next part -------------- HTML����������������������������... Download