Kouhei Sutou
null+****@clear*****
Sun Mar 27 23:43:23 JST 2016
Kouhei Sutou 2016-03-27 23:43:23 +0900 (Sun, 27 Mar 2016) New Revision: 6df750275c2659ce198f6ae0541b7f22f3b6325d https://github.com/ranguba/groonga-client-rails/commit/6df750275c2659ce198f6ae0541b7f22f3b6325d Message: Make records objects Modified files: lib/groonga/client/searcher/select/result_set.rb Modified: lib/groonga/client/searcher/select/result_set.rb (+42 -1) =================================================================== --- lib/groonga/client/searcher/select/result_set.rb 2016-03-27 23:05:57 +0900 (5105514) +++ lib/groonga/client/searcher/select/result_set.rb 2016-03-27 23:43:23 +0900 (1570a27) @@ -40,7 +40,7 @@ module Groonga end def records - @response.records + @records ||= build_records end def sources @@ -52,6 +52,12 @@ module Groonga end private + def build_records + @response.records.collect.with_index do |record, i| + Record.new(self, i, record) + end + end + def fetch_sources source_ids = {} records.collect do |record| @@ -69,6 +75,41 @@ module Groonga sources[record["_key"]] end end + + class Record + def initialize(result_set, nth, raw_record) + @result_set = result_set + @nth = nth + @raw_record = raw_record + end + + def source + @result_set.sources[@nth] + end + + def [](name) + @raw_record[normalize_name(name)] + end + + def method_missing(name, *args, &block) + return super unless args.empty? + return super unless @raw_record.key?(name.to_s) + + self[name] + end + + def respond_to_missing?(name, *args, &block) + return super unless args.empty? + return super unless @raw_record.key?(name.to_s) + + @raw_record.key?(normalize_name(name)) + end + + private + def normalize_name(name) + name.to_s + end + end end end end -------------- next part -------------- HTML����������������������������...Descargar