Kouhei Sutou
null+****@clear*****
Fri Dec 9 18:24:14 JST 2016
Kouhei Sutou 2016-12-09 18:24:14 +0900 (Fri, 09 Dec 2016) New Revision: aa208ee46c73f0dd0d885e03281d69230f6c92f5 https://github.com/ranguba/groonga-client-model/commit/aa208ee46c73f0dd0d885e03281d69230f6c92f5 Message: Create real pseudo column Modified files: lib/groonga_client_model/schema.rb Modified: lib/groonga_client_model/schema.rb (+30 -17) =================================================================== --- lib/groonga_client_model/schema.rb 2016-12-09 17:34:33 +0900 (6bc42bd) +++ lib/groonga_client_model/schema.rb 2016-12-09 18:24:14 +0900 (77461db) @@ -29,57 +29,70 @@ module GroongaClientModel end def tables - Tables.new(@raw.tables) + Tables.new(@raw, @raw.tables) end class Tables - def initialize(raw) - @raw = raw + def initialize(raw_schema, raw_tables) + @raw_schema = raw_schema + @raw_tables = raw_tables end def [](name) name = name.to_s if name.is_a?(Symbol) - raw_table = @raw[name] + raw_table = @raw_tables[name] raise Error, "table doesn't exist: <#{name.inspect}>" if raw_table.nil? - Table.new(raw_table) + Table.new(@raw_schema, raw_table) end def exist?(name) - @raw.key?(name) + @raw_tables.key?(name) end end class Table - def initialize(raw) - @raw = raw + def initialize(raw_schema, raw_table) + @raw_schema = raw_schema + @raw_table = raw_table end def name - @raw.name + @raw_table.name end def columns - raw_columns =****@raw*****("_id" => {"name" => "_id"}) - if****@raw*****_type - raw_columns = raw_columns.merge("_key" => {"name" => "_key"}) + raw_columns = {} + raw_columns["_id"] = create_pseudo_column("_id") + if @raw_table.key_type + raw_columns["_key"] = create_pseudo_column("_key") end - Columns.new(raw_columns) + Columns.new(@raw_schema, @raw_table.columns.merge(raw_columns)) + end + + private + def create_pseudo_column(name) + raw_column = { + "name" => name, + "indexes" => [], + } + Groonga::Client::Response::Schema::Column.new(@raw_schema, raw_column) end end class Columns include Enumerable - def initialize(raw) - @raw = raw + def initialize(raw_schema, raw_columns) + @raw_schema = raw_schema + @raw_columns = raw_columns end def names - @raw.keys + @raw_columns.keys end def each - @raw.each do |name, column| + @raw_columns.each do |name, column| yield(name, column) end end -------------- next part -------------- HTML����������������������������... Download