lib/dynamoid/adapter.rb in dynamoid-2.0.0 vs lib/dynamoid/adapter.rb in dynamoid-2.1.0
- old
+ new
@@ -49,11 +49,11 @@
#
# @since 0.2.0
def benchmark(method, *args)
start = Time.now
result = yield
- Dynamoid.logger.info "(#{((Time.now - start) * 1000.0).round(2)} ms) #{method.to_s.split('_').collect(&:upcase).join(' ')}#{ " - #{args.inspect}" unless args.nil? || args.empty? }"
+ Dynamoid.logger.debug "(#{((Time.now - start) * 1000.0).round(2)} ms) #{method.to_s.split('_').collect(&:upcase).join(' ')}#{ " - #{args.inspect}" unless args.nil? || args.empty? }"
return result
end
# Write an object to the adapter.
#
@@ -78,16 +78,16 @@
# @param [Array] ids to fetch, can also be a string of just one id
# @param [Hash] options: Passed to the underlying query. The :range_key option is required whenever the table has a range key,
# unless multiple ids are passed in.
#
# @since 0.2.0
- def read(table, ids, options = {})
+ def read(table, ids, options = {}, &blk)
range_key = options.delete(:range_key)
if ids.respond_to?(:each)
ids = ids.collect{|id| range_key ? [id, range_key] : id}
- batch_get_item({table => ids}, options)
+ batch_get_item({table => ids}, options, &blk)
else
options[:range_key] = range_key if range_key
get_item(table, ids, options)
end
end
@@ -142,11 +142,15 @@
[:batch_get_item, :delete_item, :get_item, :list_tables, :put_item, :truncate, :batch_write_item, :batch_delete_item].each do |m|
# Method delegation with benchmark to the underlying adapter. Faster than relying on method_missing.
#
# @since 0.2.0
- define_method(m) do |*args|
- benchmark("#{m.to_s}", *args) {adapter.send(m, *args)}
+ define_method(m) do |*args, &blk|
+ if blk.present?
+ benchmark("#{m.to_s}", *args) { adapter.send(m, *args, &blk) }
+ else
+ benchmark("#{m.to_s}", *args) { adapter.send(m, *args) }
+ end
end
end
# Delegate all methods that aren't defind here to the underlying adapter.
#