Kosuke Asami
null+****@clear*****
Mon Jul 22 15:47:02 JST 2013
Kosuke Asami 2013-07-22 15:47:02 +0900 (Mon, 22 Jul 2013) New Revision: dad198560c5b6fcc81789ebec3a5917f2ff6674d https://github.com/groonga/fluent-plugin-droonga/commit/dad198560c5b6fcc81789ebec3a5917f2ff6674d Message: adapter: add It just has the smallest feature. Added files: lib/droonga/adapter.rb test/test_adapter.rb Added: lib/droonga/adapter.rb (+48 -0) 100644 =================================================================== --- /dev/null +++ lib/droonga/adapter.rb 2013-07-22 15:47:02 +0900 (456a416) @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2013 droonga project +# +# 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 Droonga + class Adapter + class << self + def inherited(sub_class) + super + sub_class.instance_variable_set(:@commands, {}) + end + + def command(name_or_map) + if name_or_map.is_a?(Hash) + command_map = name_or_map + command_map.each do |command_name, method_name| + @commands[command_name.to_s] = method_name + end + else + name = name_or_map + method_name = name + @commands[name.to_s] = method_name + end + end + + def method_name(command) + @commands[command.to_s] + end + end + + def adapt(command, request) + __send__(self.class.method_name(command), request) + end + end +end Added: test/test_adapter.rb (+36 -0) 100644 =================================================================== --- /dev/null +++ test/test_adapter.rb 2013-07-22 15:47:02 +0900 (e17812e) @@ -0,0 +1,36 @@ +# Copyright (C) 2013 droonga project +# +# 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 "droonga/adapter" + +class AdapterTest < Test::Unit::TestCase + class AdaptTest < self + class GroongaAdapter < Droonga::Adapter + command :select + def select(request) + :selected + end + end + + def setup + @groonga_adapter = GroongaAdapter.new + end + + def test_called + request = nil + assert_equal(:selected, @groonga_adapter.adapt(:select, request)) + end + end +end -------------- next part -------------- HTML����������������������������...Download