Kouhei Sutou
null+****@clear*****
Sun Feb 9 10:32:10 JST 2014
Kouhei Sutou 2014-02-09 10:32:10 +0900 (Sun, 09 Feb 2014) New Revision: aaa6946ab8c031d3cdeed9bceaa74ff5096293ba https://github.com/droonga/grn2drn/commit/aaa6946ab8c031d3cdeed9bceaa74ff5096293ba Message: Stringify Droonga message keys Because Droonga message defines keys are string. Modified files: lib/grn2drn/converter.rb test/test-converter.rb Modified: lib/grn2drn/converter.rb (+27 -15) =================================================================== --- lib/grn2drn/converter.rb 2014-02-09 10:22:51 +0900 (2cb4721) +++ lib/grn2drn/converter.rb 2014-02-09 10:32:10 +0900 (bb95360) @@ -79,12 +79,12 @@ module Grn2Drn end { - :id => id, - :date => format_date(@options[:date] || Time.now), - :replyTo => @options[:reply_to], - :dataset => @options[:dataset], - :type => type, - :body => body, + "id" => id, + "date" => format_date(@options[:date] || Time.now), + "replyTo" => @options[:reply_to], + "dataset" => @options[:dataset], + "type" => type, + "body" => body, } end @@ -99,16 +99,28 @@ module Grn2Drn time.iso8601 end + def stringify_keys(hash) + stringified_hash = {} + hash.each do |key, value| + stringified_hash[key.to_s] = value + end + stringified_hash + end + + def command_to_body(command) + stringify_keys(command.arguments) + end + def create_table_create_command(command) - create_message("table_create", command.arguments) + create_message("table_create", command_to_body(command)) end def create_table_remove_command(command) - create_message("table_remove", command.arguments) + create_message("table_remove", command_to_body(command)) end def create_column_create_command(command) - create_message("column_create", command.arguments) + create_message("column_create", command_to_body(command)) end def split_load_command_to_add_commands(command, &block) @@ -117,32 +129,32 @@ module Grn2Drn values = JSON.parse(values) values.each do |record| body = { - :table => command[:table], + "table" => command[:table], } if record.is_a?(Hash) record = record.dup - body[:key] = record.delete("_key") + body["key"] = record.delete("_key") record_values = record else record_values = {} record.each_with_index do |value, column_index| column = columns[column_index] if column == "_key" - body[:key] = value + body["key"] = value else - record_values[column.to_sym] = value + record_values[column] = value end end end - body[:values] = record_values unless record_values.empty? + body["values"] = record_values unless record_values.empty? yield create_message("add", body) end end def create_select_command(command) - create_message("select", command.arguments) + create_message("select", command_to_body(command)) end end end Modified: test/test-converter.rb (+93 -93) =================================================================== --- test/test-converter.rb 2014-02-09 10:22:51 +0900 (5d2e7a7) +++ test/test-converter.rb 2014-02-09 10:32:10 +0900 (fddb1ab) @@ -59,17 +59,17 @@ table_create Terms TABLE_PAT_KEY ShortText \ COMMAND assert_equal([ { - :id => "test:0", - :date => formatted_date, - :replyTo => reply_to, - :dataset => dataset, - :type => "table_create", - :body => { - :name => "Terms", - :flags => "TABLE_PAT_KEY", - :key_type => "ShortText", - :default_tokenizer => "TokenBigram", - :normalizer => "NormalizerAuto", + "id" => "test:0", + "date" => formatted_date, + "replyTo" => reply_to, + "dataset" => dataset, + "type" => "table_create", + "body" => { + "name" => "Terms", + "flags" => "TABLE_PAT_KEY", + "key_type" => "ShortText", + "default_tokenizer" => "TokenBigram", + "normalizer" => "NormalizerAuto", }, }, ], @@ -84,17 +84,17 @@ column_create Terms Users_name COLUMN_INDEX|WITH_POSITION Users name COMMAND assert_equal([ { - :id => "test:0", - :date => formatted_date, - :replyTo => reply_to, - :dataset => dataset, - :type => "column_create", - :body => { - :table => "Terms", - :name => "Users_name", - :flags => "COLUMN_INDEX|WITH_POSITION", - :type => "Users", - :source => "name", + "id" => "test:0", + "date" => formatted_date, + "replyTo" => reply_to, + "dataset" => dataset, + "type" => "column_create", + "body" => { + "table" => "Terms", + "name" => "Users_name", + "flags" => "COLUMN_INDEX|WITH_POSITION", + "type" => "Users", + "source" => "name", }, }, ], @@ -113,16 +113,16 @@ load --table Users COMMAND assert_equal([ { - :id => "test:0", - :date => formatted_date, - :replyTo => reply_to, - :dataset => dataset, - :type => "add", - :body => { - :table => "Users", - :key => "user", - :values => { - :name => "Abe Shinzo", + "id" => "test:0", + "date" => formatted_date, + "replyTo" => reply_to, + "dataset" => dataset, + "type" => "add", + "body" => { + "table" => "Users", + "key" => "user", + "values" => { + "name" => "Abe Shinzo", }, }, }, @@ -142,44 +142,44 @@ load --table Users COMMAND assert_equal([ { - :id => "test:0", - :date => formatted_date, - :replyTo => reply_to, - :dataset => dataset, - :type => "add", - :body => { - :table => "Users", - :key => "user0", - :values => { - :name => "Abe Shinzo", + "id" => "test:0", + "date" => formatted_date, + "replyTo" => reply_to, + "dataset" => dataset, + "type" => "add", + "body" => { + "table" => "Users", + "key" => "user0", + "values" => { + "name" => "Abe Shinzo", }, }, }, { - :id => "test:1", - :date => formatted_date, - :replyTo => reply_to, - :dataset => dataset, - :type => "add", - :body => { - :table => "Users", - :key => "user1", - :values => { - :name => "Noda Yoshihiko", + "id" => "test:1", + "date" => formatted_date, + "replyTo" => reply_to, + "dataset" => dataset, + "type" => "add", + "body" => { + "table" => "Users", + "key" => "user1", + "values" => { + "name" => "Noda Yoshihiko", }, }, }, { - :id => "test:2", - :date => formatted_date, - :replyTo => reply_to, - :dataset => dataset, - :type => "add", - :body => { - :table => "Users", - :key => "user2", - :values => { - :name => "Kan Naoto", + "id" => "test:2", + "date" => formatted_date, + "replyTo" => reply_to, + "dataset" => dataset, + "type" => "add", + "body" => { + "table" => "Users", + "key" => "user2", + "values" => { + "name" => "Kan Naoto", }, }, }, @@ -195,15 +195,15 @@ select --filter "age<=30" --output_type "json" --table "Users" COMMAND assert_equal([ { - :id => "test:0", - :date => formatted_date, - :replyTo => reply_to, - :dataset => dataset, - :type => "select", - :body => { - :table => "Users", - :filter => "age<=30", - :output_type => "json", + "id" => "test:0", + "date" => formatted_date, + "replyTo" => reply_to, + "dataset" => dataset, + "type" => "select", + "body" => { + "table" => "Users", + "filter" => "age<=30", + "output_type" => "json", }, }, ], @@ -220,31 +220,31 @@ column_create Terms Users_name COLUMN_INDEX|WITH_POSITION Users name COMMANDS assert_equal([ { - :id => "test:0", - :date => formatted_date, - :replyTo => reply_to, - :dataset => dataset, - :type => "table_create", - :body => { - :name => "Terms", - :flags => "TABLE_PAT_KEY", - :key_type => "ShortText", - :default_tokenizer => "TokenBigram", - :normalizer => "NormalizerAuto", + "id" => "test:0", + "date" => formatted_date, + "replyTo" => reply_to, + "dataset" => dataset, + "type" => "table_create", + "body" => { + "name" => "Terms", + "flags" => "TABLE_PAT_KEY", + "key_type" => "ShortText", + "default_tokenizer" => "TokenBigram", + "normalizer" => "NormalizerAuto", }, }, { - :id => "test:1", - :date => formatted_date, - :replyTo => reply_to, - :dataset => dataset, - :type => "column_create", - :body => { - :table => "Terms", - :name => "Users_name", - :flags => "COLUMN_INDEX|WITH_POSITION", - :type => "Users", - :source => "name", + "id" => "test:1", + "date" => formatted_date, + "replyTo" => reply_to, + "dataset" => dataset, + "type" => "column_create", + "body" => { + "table" => "Terms", + "name" => "Users_name", + "flags" => "COLUMN_INDEX|WITH_POSITION", + "type" => "Users", + "source" => "name", }, }, ], -------------- next part -------------- HTML����������������������������... 다운로드