lib/endeca/document.rb in primedia-endeca-0.12.0 vs lib/endeca/document.rb in primedia-endeca-0.14.0

- old
+ new

@@ -4,12 +4,12 @@ # declared with reader to be accessible on the object. # # The +reader+ declaration provided by Readers can also handle basic data transformations (i.e. # typecasting) and a few basic examples are provided (i.e. +integer_reader+). class Document + include Readers extend ClassToProc - extend Readers extend Transformer inherited_accessor :mappings, {} inherited_property :path inherited_property :default_params, {} @@ -91,19 +91,20 @@ end # Returns the first Document matching the query options. def self.first(query_options={}) - response = request(query_options) - if response['AggrRecords'] - record = response['AggrRecords'].first['Records'].first + response = request(query_options) + record = if response['AggrRecords'] + response['AggrRecords'].first['Records'].first + elsif response['Records'] + response['Records'].first else - record = response['Records'].first + nil end + record && new(record) - rescue Exception - nil end # Returns all Documents matching the query options. def self.all(query_options={}) get_collection_class.new(request(query_options), self) @@ -129,8 +130,7 @@ transform_query_options(query_options) else URI.unescape(query_options) end end - end end