Kouhei Sutou
null+****@clear*****
Wed Nov 28 12:53:07 JST 2012
Kouhei Sutou 2012-11-28 12:53:07 +0900 (Wed, 28 Nov 2012) New Revision: 3c9661975eab43f01162423143b7220997d8468d https://github.com/groonga/groonga-command/commit/3c9661975eab43f01162423143b7220997d8468d Log: Support on_load_header with --columns option Modified files: lib/groonga/command/load.rb lib/groonga/command/parser.rb test/test-parser.rb Modified: lib/groonga/command/load.rb (+16 -0) =================================================================== --- lib/groonga/command/load.rb 2012-11-28 12:41:03 +0900 (3a477ff) +++ lib/groonga/command/load.rb 2012-11-28 12:53:07 +0900 (347e3a4) @@ -35,6 +35,22 @@ module Groonga ] end end + + attr_writer :columns + def initialize(*argumetns) + super + @columns = nil + end + + def columns + @columns ||= parse_columns(self[:columns]) + end + + private + def parse_columns(columns) + return columns if columns.nil? + columns.split(/\s*,\s*/) + end end end end Modified: lib/groonga/command/parser.rb (+7 -4) =================================================================== --- lib/groonga/command/parser.rb 2012-11-28 12:41:03 +0900 (2f38269) +++ lib/groonga/command/parser.rb 2012-11-28 12:53:07 +0900 (86ce9ad) @@ -279,14 +279,13 @@ module Groonga @command.original_source << spaces << start_json @buffer = rest @json_parser = Yajl::Parser.new - @json_first_completed = true @json_parser.on_parse_complete = lambda do |object| - if object.is_a?(Array) and @json_first_completed + if object.is_a?(Array) and****@comma*****? + @command.columns = object on_load_header(@command, object) else on_load_value(@command, object) end - @json_first_completed = false @load_value_completed = true end @in_load_values = true @@ -335,10 +334,14 @@ module Groonga def process_command if****@comma***** == "load" on_load_start(@command) + if****@comma***** + on_load_header(@command, @command.columns) + end if @command[:values] values = Yajl::Parser.parse(@command[:values]) - if values.first.is_a?(Array) + if****@comma*****? and values.first.is_a?(Array) header = values.shift + @command.columns = header on_load_header(@command, header) end values.each do |value| Modified: test/test-parser.rb (+29 -1) =================================================================== --- test/test-parser.rb 2012-11-28 12:41:03 +0900 (b86260f) +++ test/test-parser.rb 2012-11-28 12:53:07 +0900 (0823891) @@ -158,7 +158,35 @@ class ParserTest < Test::Unit::TestCase class MultiLineTest < self class BracketTest < self - def test_bracket + def test_have_columns + @parser << <<-EOC +load --table Users --columns "_key, name" +[ +["alice", "Alice"] +] +EOC + expected_events = [] + expected_events << [:load_start, <<-EOC.chomp] +load --table Users --columns "_key, name" +EOC + expected_events << [:load_header, <<-EOC.chomp, ["_key", "name"]] +load --table Users --columns "_key, name" +EOC + expected_events << [:load_value, <<-EOC.chomp, ["alice", "Alice"]] +load --table Users --columns "_key, name" +[ +["alice", "Alice"] +EOC + expected_events << [:load_complete, <<-EOC.chomp] +load --table Users --columns "_key, name" +[ +["alice", "Alice"] +] +EOC + assert_equal(expected_events, @events) + end + + def test_no_columns @parser << <<-EOC load --table Users [ -------------- next part -------------- HTML����������������������������... Download