lib/elasticsearch/model/response/result.rb in elasticsearch-model-0.1.1 vs lib/elasticsearch/model/response/result.rb in elasticsearch-model-0.1.2

- old
+ new

@@ -15,18 +15,32 @@ # def initialize(attributes={}) @result = Hashie::Mash.new(attributes) end + # Return document `_id` as `id` + # + def id + @result['_id'] + end + + # Return document `_type` as `_type` + # + def type + @result['_type'] + end + # Delegate methods to `@result` or `@result._source` # - def method_missing(method_name, *arguments) + def method_missing(name, *arguments) case - when @result.respond_to?(method_name.to_sym) - @result.__send__ method_name.to_sym, *arguments - when @result._source && @result._source.respond_to?(method_name.to_sym) - @result._source.__send__ method_name.to_sym, *arguments + when name.to_s.end_with?('?') + @result.__send__(name, *arguments) || ( @result._source && @result._source.__send__(name, *arguments) ) + when @result.respond_to?(name) + @result.__send__ name, *arguments + when @result._source && @result._source.respond_to?(name) + @result._source.__send__ name, *arguments else super end end @@ -41,10 +55,9 @@ def as_json(options={}) @result.as_json(options) end # TODO: #to_s, #inspect, with support for Pry - end end end end