ccp 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/ccp/kvs/core.rb CHANGED
@@ -6,6 +6,8 @@ module Ccp
6
6
  def del(k) ; raise NotImplementedError, "subclass resposibility"; end
7
7
  def keys ; raise NotImplementedError, "subclass resposibility"; end
8
8
  def read! ; keys.inject({}){|h,k| h[k] = get(k); h } ; end
9
+ def exist?(k); !! get(k) ; end
10
+ def key?(k) ; exist?(k) ; end
9
11
 
10
12
  def open(*) ; end
11
13
  def close ; end
@@ -25,6 +25,18 @@ module Ccp
25
25
  end
26
26
 
27
27
  private
28
+ # Check ecode and then raise. too boring... The library should implement this as atomic operation!
29
+ def atomic(&block)
30
+ raise NotImplementedError, "tc keep ecode until new erros occured"
31
+
32
+ if tokyo_error?
33
+ raise "tc already error before atomic: #{@db.ecode}"
34
+ end
35
+ v = block.call
36
+ tokyo_error! if tokyo_error?
37
+ return v
38
+ end
39
+
28
40
  def tokyo_error!(label = nil)
29
41
  raise Ccp::Kvs::Tokyo::Error, "%s%s (%s)" % [label, error_message, @source]
30
42
  end
@@ -47,6 +47,11 @@ module Ccp
47
47
  end
48
48
  end
49
49
 
50
+ def exist?(k)
51
+ tryR("exist?")
52
+ return @db.has_key?(k.to_s)
53
+ end
54
+
50
55
  def count
51
56
  tryR("count")
52
57
  return @db.rnum
data/lib/ccp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ccp
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
@@ -10,4 +10,6 @@ describe Ccp::Kvs::Core do
10
10
  it { should respond_to("del") }
11
11
  it { should respond_to("keys") }
12
12
  it { should respond_to("touch") }
13
+ it { should respond_to("exist?") }
14
+ it { should respond_to("key?") }
13
15
  end
@@ -275,4 +275,16 @@ describe Ccp::Kvs::Tokyo::Cabinet do
275
275
  end
276
276
  end
277
277
 
278
+ ######################################################################
279
+ ### exist?
280
+
281
+ describe "#exist?" do
282
+ specify do
283
+ put(:foo, 1)
284
+
285
+ kvs.R!
286
+ kvs.exist?(:foo).should be
287
+ kvs.exist?(:bar).should_not be
288
+ end
289
+ end
278
290
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ccp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 3
10
- version: 0.3.3
9
+ - 4
10
+ version: 0.3.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - maiha
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-08-30 00:00:00 Z
18
+ date: 2013-09-04 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activesupport