Kouhei Sutou
null+****@clear*****
Sun Nov 24 18:26:20 JST 2013
Kouhei Sutou 2013-11-24 18:26:20 +0900 (Sun, 24 Nov 2013) New Revision: 83a6ae532b3d41b6cc5bbb940351c447441c7419 https://github.com/droonga/fluent-plugin-droonga/commit/83a6ae532b3d41b6cc5bbb940351c447441c7419 Message: Extract commaon plugin registration code to a module Added files: lib/droonga/plugin_registerable.rb Modified files: lib/droonga/distributor_plugin.rb lib/droonga/handler_plugin.rb Modified: lib/droonga/distributor_plugin.rb (+2 -25) =================================================================== --- lib/droonga/distributor_plugin.rb 2013-11-24 18:14:07 +0900 (66cfe53) +++ lib/droonga/distributor_plugin.rb 2013-11-24 18:26:20 +0900 (db67cbc) @@ -15,34 +15,11 @@ # 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/plugin_repository" +require "droonga/plugin_registerable" module Droonga class DistributorPlugin - @@repository = PluginRepository.new - - class << self - def inherited(sub_class) - super - sub_class.instance_variable_set(:@command_mapper, CommandMapper.new) - end - - def repository - @@repository - end - - def command(name_or_map) - @command_mapper.register(name_or_map) - end - - def method_name(command) - @command_mapper[command] - end - - def processable?(command) - not method_name(command).nil? - end - end + extend PluginRegisterable def initialize(distributor) @distributor = distributor Modified: lib/droonga/handler_plugin.rb (+3 -26) =================================================================== --- lib/droonga/handler_plugin.rb 2013-11-24 18:14:07 +0900 (b103748) +++ lib/droonga/handler_plugin.rb 2013-11-24 18:26:20 +0900 (072461b) @@ -15,34 +15,11 @@ # 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/plugin_repository" +require "droonga/plugin_registerable" module Droonga class HandlerPlugin - @@repository = PluginRepository.new - - class << self - def inherited(sub_class) - super - sub_class.instance_variable_set(:@command_mapper, CommandMapper.new) - end - - def repository - @@repository - end - - def command(name_or_map) - @command_mapper.register(name_or_map) - end - - def method_name(command) - @command_mapper[command] - end - - def handlable?(command) - not method_name(command).nil? - end - end + extend PluginRegisterable def initialize(handler) @handler = handler @@ -57,7 +34,7 @@ module Droonga end def handlable?(command) - self.class.handlable?(command) + self.class.processable?(command) end def handle(command, request, *arguments) Added: lib/droonga/plugin_registerable.rb (+50 -0) 100644 =================================================================== --- /dev/null +++ lib/droonga/plugin_registerable.rb 2013-11-24 18:26:20 +0900 (a2b405d) @@ -0,0 +1,50 @@ +# -*- 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 + +require "droonga/plugin_repository" + +module Droonga + module PluginRegisterable + class << self + def extended(plugin_class) + super + plugin_class.class_variable_set(:@@repository, PluginRepository.new) + end + end + + def repository + class_variable_get(:@@repository) + end + + def inherited(sub_class) + super + sub_class.instance_variable_set(:@command_mapper, CommandMapper.new) + end + + def command(name_or_map) + @command_mapper.register(name_or_map) + end + + def method_name(command) + @command_mapper[command] + end + + def processable?(command) + not method_name(command).nil? + end + end +end -------------- next part -------------- HTML����������������������������...Download