YUKI Hiroshi
null+****@clear*****
Mon Apr 28 17:10:19 JST 2014
YUKI Hiroshi 2014-04-28 17:10:19 +0900 (Mon, 28 Apr 2014) New Revision: d151dda625f477b8ec0bb74e905a17dbb7d49ca6 https://github.com/droonga/droonga-engine/commit/d151dda625f477b8ec0bb74e905a17dbb7d49ca6 Message: groonga: Extract validation logic for the table name Modified files: lib/droonga/plugins/groonga/column_create.rb lib/droonga/plugins/groonga/column_list.rb lib/droonga/plugins/groonga/column_remove.rb lib/droonga/plugins/groonga/column_rename.rb lib/droonga/plugins/groonga/delete.rb lib/droonga/plugins/groonga/generic_command.rb lib/droonga/plugins/groonga/table_remove.rb Modified: lib/droonga/plugins/groonga/column_create.rb (+1 -7) =================================================================== --- lib/droonga/plugins/groonga/column_create.rb 2014-04-28 16:44:37 +0900 (c19120a) +++ lib/droonga/plugins/groonga/column_create.rb 2014-04-28 17:10:19 +0900 (19ab3ca) @@ -27,13 +27,7 @@ module Droonga command_class = ::Groonga::Command.find("column_create") @command = command_class.new("column_create", request) - table_name = @command["table"] - if table_name.nil? or @context[table_name].nil? - message = "table doesn't exist: <#{table_name.to_s}>" - raise CommandError.new(:status => Status::INVALID_ARGUMENT, - :message => message, - :result => false) - end + table_name = valid_table_name("table") if****@comma*****_index? define_index(table_name) Modified: lib/droonga/plugins/groonga/column_list.rb (+1 -6) =================================================================== --- lib/droonga/plugins/groonga/column_list.rb 2014-04-28 16:44:37 +0900 (5406e4f) +++ lib/droonga/plugins/groonga/column_list.rb 2014-04-28 17:10:19 +0900 (97275ba) @@ -38,12 +38,7 @@ module Droonga command_class = ::Groonga::Command.find("column_list") @command = command_class.new("column_list", request) - table_name = @command["table"] - if table_name.nil? or @context[table_name].nil? - message = "table doesn't exist: <#{table_name.to_s}>" - raise CommandError.new(:status => Status::INVALID_ARGUMENT, - :message => message) - end + table_name = valid_table_name("table") columns = list_columns(table_name) [HEADER, *columns] Modified: lib/droonga/plugins/groonga/column_remove.rb (+1 -7) =================================================================== --- lib/droonga/plugins/groonga/column_remove.rb 2014-04-28 16:44:37 +0900 (0990c46) +++ lib/droonga/plugins/groonga/column_remove.rb 2014-04-28 17:10:19 +0900 (5d1592e) @@ -27,13 +27,7 @@ module Droonga command_class = ::Groonga::Command.find("column_remove") @command = command_class.new("column_remove", request) - table_name = @command["table"] - if table_name.nil? or @context[table_name].nil? - message = "table doesn't exist: <#{table_name.to_s}>" - raise CommandError.new(:status => Status::INVALID_ARGUMENT, - :message => message, - :result => false) - end + table_name = valid_table_name("table") column_name = @command["name"] if column_name.nil? or @context[table_name].column(column_name).nil? Modified: lib/droonga/plugins/groonga/column_rename.rb (+1 -7) =================================================================== --- lib/droonga/plugins/groonga/column_rename.rb 2014-04-28 16:44:37 +0900 (f8c871c) +++ lib/droonga/plugins/groonga/column_rename.rb 2014-04-28 17:10:19 +0900 (49f45e0) @@ -27,13 +27,7 @@ module Droonga command_class = ::Groonga::Command.find("column_rename") @command = command_class.new("column_rename", request) - table_name = @command["table"] - if table_name.nil? or @context[table_name].nil? - message = "table doesn't exist: <#{table_name.to_s}>" - raise CommandError.new(:status => Status::INVALID_ARGUMENT, - :message => message, - :result => false) - end + table_name = valid_table_name("table") column_name = @command["name"] if column_name.nil? or @context[table_name].column(column_name).nil? Modified: lib/droonga/plugins/groonga/delete.rb (+4 -10) =================================================================== --- lib/droonga/plugins/groonga/delete.rb 2014-04-28 16:44:37 +0900 (080f363) +++ lib/droonga/plugins/groonga/delete.rb 2014-04-28 17:10:19 +0900 (b7c8ff9) @@ -27,12 +27,13 @@ module Droonga command_class = ::Groonga::Command.find("delete") @command = command_class.new("delete", request) - table_name = @command["table"] + table_name = valid_table_name("table") + key = @command["key"] id = @command["id"] filter = @command["filter"] - validate_parameters(table_name, key, id, filter) + validate_parameters(key, id, filter) table = @context[table_name] if key @@ -47,14 +48,7 @@ module Droonga end private - def validate_parameters(table_name, key, id, filter) - if table_name.nil? or @context[table_name].nil? - message = "table doesn't exist: <#{table_name}>" - raise CommandError.new(:status => Status::INVALID_ARGUMENT, - :message => message, - :result => false) - end - + def validate_parameters(key, id, filter) if key.nil? and id.nil? and filter.nil? message = "you must specify \"key\", \"id\", or \"filter\"" raise CommandError.new(:status => Status::INVALID_ARGUMENT, Modified: lib/droonga/plugins/groonga/generic_command.rb (+20 -0) =================================================================== --- lib/droonga/plugins/groonga/generic_command.rb 2014-04-28 16:44:37 +0900 (9613da7) +++ lib/droonga/plugins/groonga/generic_command.rb 2014-04-28 17:10:19 +0900 (d869830) @@ -58,6 +58,26 @@ module Droonga header.push(error_message) unless error_message.empty? header end + + def valid_table_name(name) + table_name = @command[name] + + if table_name.nil? + message = "you must specify table via \"#{name}\"" + raise CommandError.new(:status => Status::INVALID_ARGUMENT, + :message => message, + :result => false) + end + + if @context[table_name].nil? + message = "table not found: <#{table_name.to_s}>" + raise CommandError.new(:status => Status::INVALID_ARGUMENT, + :message => message, + :result => false) + end + + table_name + end end end end Modified: lib/droonga/plugins/groonga/table_remove.rb (+1 -6) =================================================================== --- lib/droonga/plugins/groonga/table_remove.rb 2014-04-28 16:44:37 +0900 (a6428b6) +++ lib/droonga/plugins/groonga/table_remove.rb 2014-04-28 17:10:19 +0900 (368e2c4) @@ -27,12 +27,7 @@ module Droonga command_class = ::Groonga::Command.find("table_remove") @command = command_class.new("table_remove", request) - name = @command["name"] - if name.nil? or @context[name].nil? - raise CommandError.new(:status => Status::INVALID_ARGUMENT, - :message => "table not found", - :result => false) - end + table_name = valid_table_name("name") ::Groonga::Schema.define(:context => @context) do |schema| schema.remove_table(name) -------------- next part -------------- HTML����������������������������... 下載