Kouhei Sutou
null+****@clear*****
Fri Feb 7 15:27:06 JST 2014
Kouhei Sutou 2014-02-07 15:27:06 +0900 (Fri, 07 Feb 2014) New Revision: 7aba30996da7edcd9a5dadb71aa88841bd90ec10 https://github.com/droonga/fluent-plugin-droonga/commit/7aba30996da7edcd9a5dadb71aa88841bd90ec10 Message: Extract generic code in adapter as Pluggable Copied files: lib/droonga/plugin/metadata/adapter_message.rb (from lib/droonga/adapter.rb) Modified files: lib/droonga/adapter.rb lib/droonga/plugin_loader.rb Renamed files: lib/droonga/pluggable.rb (from lib/droonga/adapter/message_configuration.rb) lib/droonga/plugin/metadata/plugin.rb (from lib/droonga/adapter/plugin_configuration.rb) Modified: lib/droonga/adapter.rb (+6 -21) =================================================================== --- lib/droonga/adapter.rb 2014-02-07 15:05:31 +0900 (0aadcf2) +++ lib/droonga/adapter.rb 2014-02-07 15:27:06 +0900 (e3f2d36) @@ -13,33 +13,21 @@ # 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/pluggable" +require "droonga/plugin/metadata/adapter_message" + module Droonga class Adapter - class << self - def sub_classes - @@sub_classes ||= [] - end - - def inherited(sub_class) - super - sub_classes << sub_class - end - - def plugin - PluginConfiguration.new(self) - end + extend Pluggable + class << self def message - MessageConfiguration.new(self) + Plugin::Metadata::AdapterMessage.new(self) end def id options[:id] || name || object_id.to_s end - - def options - @options ||= {} - end end def adapt_input(input_message) @@ -49,6 +37,3 @@ module Droonga end end end - -require "droonga/adapter/plugin_configuration" -require "droonga/adapter/message_configuration" Renamed: lib/droonga/pluggable.rb (+20 -21) 57% =================================================================== --- lib/droonga/adapter/message_configuration.rb 2014-02-07 15:05:31 +0900 (bc005b6) +++ lib/droonga/pluggable.rb 2014-02-07 15:27:06 +0900 (974670d) @@ -13,33 +13,32 @@ # 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 MessageConfiguration - def initialize(adapter_class) - @adapter_class = adapter_class - end +require "droonga/plugin/metadata/plugin" - def input_pattern - configuration[:input_pattern] +module Droonga + module Pluggable + class << self + def extended(pluggable_class) + super + pluggable_class.class_variable_set(:@@sub_classes, []) end + end - def input_pattern=(pattern) - configuration[:input_pattern] = pattern - end + def sub_classes + class_variable_get(:@@sub_classes) + end - def output_pattern - configuration[:output_pattern] - end + def inherited(sub_class) + super + sub_classes << sub_class + end - def output_pattern=(pattern) - configuration[:output_pattern] = pattern - end + def plugin + Plugin::Metadata::Plugin.new(self) + end - private - def configuration - @adapter_class.options[:message] ||= {} - end + def options + @options ||= {} end end end Copied: lib/droonga/plugin/metadata/adapter_message.rb (+27 -34) 54% =================================================================== --- lib/droonga/adapter.rb 2014-02-07 15:05:31 +0900 (0aadcf2) +++ lib/droonga/plugin/metadata/adapter_message.rb 2014-02-07 15:27:06 +0900 (9c8d68c) @@ -14,41 +14,34 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA module Droonga - class Adapter - class << self - def sub_classes - @@sub_classes ||= [] + module Plugin + module Metadata + class AdapterMessage + def initialize(adapter_class) + @adapter_class = adapter_class + end + + def input_pattern + configuration[:input_pattern] + end + + def input_pattern=(pattern) + configuration[:input_pattern] = pattern + end + + def output_pattern + configuration[:output_pattern] + end + + def output_pattern=(pattern) + configuration[:output_pattern] = pattern + end + + private + def configuration + @adapter_class.options[:message] ||= {} + end end - - def inherited(sub_class) - super - sub_classes << sub_class - end - - def plugin - PluginConfiguration.new(self) - end - - def message - MessageConfiguration.new(self) - end - - def id - options[:id] || name || object_id.to_s - end - - def options - @options ||= {} - end - end - - def adapt_input(input_message) - end - - def adapt_output(output_message) end end end - -require "droonga/adapter/plugin_configuration" -require "droonga/adapter/message_configuration" Renamed: lib/droonga/plugin/metadata/plugin.rb (+16 -14) 66% =================================================================== --- lib/droonga/adapter/plugin_configuration.rb 2014-02-07 15:05:31 +0900 (f11320c) +++ lib/droonga/plugin/metadata/plugin.rb 2014-02-07 15:27:06 +0900 (b279426) @@ -14,23 +14,25 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA module Droonga - class Adapter - class PluginConfiguration - def initialize(adapter_class) - @adapter_class = adapter_class - end + module Plugin + module Metadata + class Plugin + def initialize(plugin_class) + @plugin_class = plugin_class + end - def name - configuration[:name] - end + def name + configuration[:name] + end - def name=(name) - configuration[:name] = name - end + def name=(name) + configuration[:name] = name + end - private - def configuration - @adapter_class.options[:plugin] ||= {} + private + def configuration + @plugin_class.options[:plugin] ||= {} + end end end end Modified: lib/droonga/plugin_loader.rb (+2 -0) =================================================================== --- lib/droonga/plugin_loader.rb 2014-02-07 15:05:31 +0900 (c19cbe0) +++ lib/droonga/plugin_loader.rb 2014-02-07 15:27:06 +0900 (ca197a9) @@ -31,6 +31,7 @@ module Droonga loader.load end end + Pathname.glob("#{load_path}/droonga/plugins/*.rb") do |plugin_path| relative_plugin_path = plugin_path.relative_path_from(Pathname(load_path)) @@ -47,6 +48,7 @@ module Droonga end def load + return if @type == "metadata" require "droonga/plugin/#{@type}/#{@name}" end end -------------- next part -------------- HTML����������������������������...Download