lib/couchbase/operations/get.rb in couchbase-jruby-client-0.1.1 vs lib/couchbase/operations/get.rb in couchbase-jruby-client-0.1.2
- old
+ new
@@ -1,5 +1,22 @@
+# Author:: Mike Evans <mike@urlgonomics.com>
+# Copyright:: 2013 Urlgonomics LLC.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
module Couchbase::Operations
module Get
# Obtain an object stored in Couchbase by given key.
#
@@ -126,29 +143,23 @@
#
# @example Get and lock multiple keys for chosen period in seconds
# c.get("foo" => 10, "bar" => 20, :lock => true)
# #=> {"foo" => val1, "bar" => val2}
#
- def get(*args)
+ def get(*args, &block)
key, options = expand_get_args(args)
if async?
- if block_given?
- async_get(key, &Proc.new)
- else
- async_get(key)
- end
+ async_get(key, &block)
+ # if block_given?
+ # async_get(key, &Proc.new)
+ # else
+ # async_get(key)
+ # end
else
sync_block_error if block_given?
- case key
- when String, Symbol
- get_single(key, options)
- when Array
- get_bulk(key, options)
- when Hash
- get_and_touch(key, options)
- end
+ get_key(key, options)
end
end
def [](key, options = {})
get(key, options)
@@ -175,17 +186,28 @@
when String, Symbol
meta = { op: :get, key: key }
future = client.asyncGet(key)
when Array
meta = { op: :get }
- future = client.asyncGetBulk(keys)
+ future = client.asyncGetBulk(key)
when Hash
# async_get_and_touch(key, options, &block)
end
register_future(future, meta, &Proc.new) if block_given?
end
private
+
+ def get_key(key, options)
+ case key
+ when String, Symbol
+ get_single(key, options)
+ when Array
+ get_bulk(key, options)
+ when Hash
+ get_and_touch(key, options)
+ end
+ end
def expand_get_args(args)
options = extract_options_hash(args)
key = args.size == 1 ? args.first : args