Kouhei Sutou
null+****@clear*****
Tue Aug 9 11:39:45 JST 2016
Kouhei Sutou 2016-08-09 11:39:45 +0900 (Tue, 09 Aug 2016) New Revision: 3e32866b7225939f07bf4fe1ff623092c6b932dc https://github.com/groonga/groonga-schema/commit/3e32866b7225939f07bf4fe1ff623092c6b932dc Message: Use Groonga::Command Modified files: lib/groonga-schema/diff.rb lib/groonga-schema/plugin.rb test/test-diff.rb test/test-plugin.rb Modified: lib/groonga-schema/diff.rb (+19 -11) =================================================================== --- lib/groonga-schema/diff.rb 2016-08-09 11:24:30 +0900 (98966af) +++ lib/groonga-schema/diff.rb 2016-08-09 11:39:45 +0900 (a86810b) @@ -71,33 +71,41 @@ module GroongaSchema class GroongaCommandListConverter def initialize(diff) @diff = diff - @buffer = "" + @grouped_list = [] end def convert - @buffer.clear + @grouped_list.clear + convert_added_plugins convert_removed_plugins - @buffer + + meaningful_grouped_list = @grouped_list.reject do |group| + group.empty? + end + formatted_grouped_list = meaningful_grouped_list.collect do |group| + command_list = "" + group.each do |command| + command_list << "#{command.to_command_format}\n" + end + command_list + end + formatted_grouped_list.join("\n") end private def convert_added_plugins return if****@diff*****_plugins.empty? - @buffer << "\n" unles****@buffe*****? - @diff.added_plugins.sort_by(&:name).each do |plugin| - @buffer << "plugin_register #{plugin.name}\n" - end + sorted_plugins =****@diff*****_plugins.sort_by(&:name) + @grouped_list << sorted_plugins.collect(&:to_register_groonga_command) end def convert_removed_plugins return if****@diff*****_plugins.empty? - @buffer << "\n" unles****@buffe*****? - @diff.removed_plugins.sort_by(&:name).each do |plugin| - @buffer << "plugin_unregister #{plugin.name}\n" - end + sorted_plugins =****@diff*****_plugins.sort_by(&:name) + @grouped_list << sorted_plugins.collect(&:to_unregister_groonga_command) end end end Modified: lib/groonga-schema/plugin.rb (+10 -0) =================================================================== --- lib/groonga-schema/plugin.rb 2016-08-09 11:24:30 +0900 (702f3d4) +++ lib/groonga-schema/plugin.rb 2016-08-09 11:39:45 +0900 (feb6d84) @@ -14,6 +14,8 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +require "groonga/command" + module GroongaSchema class Plugin attr_reader :name @@ -26,5 +28,13 @@ module GroongaSchema @name == other.name end + + def to_register_groonga_command + Groonga::Command::PluginRegister.new(:name => @name) + end + + def to_unregister_groonga_command + Groonga::Command::PluginUnregister.new(:name => @name) + end end end Modified: test/test-diff.rb (+2 -2) =================================================================== --- test/test-diff.rb 2016-08-09 11:24:30 +0900 (315c8d8) +++ test/test-diff.rb 2016-08-09 11:39:45 +0900 (2e4f2f2) @@ -43,9 +43,9 @@ class DiffTest < Test::Unit::TestCase @diff.added_plugins << plugin("token_filters/stem") @diff.removed_plugins << plugin("token_filters/stop_word") assert_equal(<<-LIST, @diff.to_groonga_command_list) -plugin_register token_filters/stem +plugin_register --name "token_filters/stem" -plugin_unregister token_filters/stop_word +plugin_unregister --name "token_filters/stop_word" LIST end end Modified: test/test-plugin.rb (+12 -0) =================================================================== --- test/test-plugin.rb 2016-08-09 11:24:30 +0900 (f2b91de) +++ test/test-plugin.rb 2016-08-09 11:39:45 +0900 (179b92f) @@ -28,4 +28,16 @@ class PluginTest < Test::Unit::TestCase assert_not_equal(plugin1, plugin2) end end + + test "#to_register_groonga_command" do + plugin = GroongaSchema::Plugin.new("token_filters/stem") + assert_equal("plugin_register --name \"token_filters/stem\"", + plugin.to_register_groonga_command.to_command_format) + end + + test "#to_unregister_groonga_command" do + plugin = GroongaSchema::Plugin.new("token_filters/stem") + assert_equal("plugin_unregister --name \"token_filters/stem\"", + plugin.to_unregister_groonga_command.to_command_format) + end end -------------- next part -------------- HTML����������������������������...Download