ccp 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,6 +35,7 @@ module Ccp
35
35
  # bulk operation
36
36
  def read ; keys.inject({}){|h,k| h[k] = get(k); h } ; end
37
37
  def write(h) ; h.each_pair{|k,v| set(k,v)} ; end
38
+ def clear ; keys.each{|k| del(k)} ; end
38
39
  end
39
40
  end
40
41
  end
@@ -13,6 +13,7 @@ module Ccp
13
13
  def set(k,v) ; @db[k.to_s] = encode(v).to_s; end
14
14
  def del(k) ; decode(@db.delete(k.to_s)) ; end
15
15
  def count ; @db.size ; end
16
+ def clear ; @db.clear ; end
16
17
  end
17
18
  end
18
19
  end
@@ -17,6 +17,7 @@ unless load_error
17
17
  def count ; R{ super }; end
18
18
  def read ; R{ super }; end
19
19
  def write(h) ; W{ super }; end
20
+ def clear ; W{ super }; end
20
21
 
21
22
  # enum
22
23
  def each(&b) ; R{ super }; end
@@ -77,6 +77,11 @@ module Ccp
77
77
  return h
78
78
  end
79
79
 
80
+ def clear
81
+ tryW("clear")
82
+ @db.clear or kyoto_error!("clear: ")
83
+ end
84
+
80
85
  ######################################################################
81
86
  ### iterator
82
87
 
@@ -17,6 +17,7 @@ unless load_error
17
17
  def count ; R{ super }; end
18
18
  def read ; R{ super }; end
19
19
  def write(h) ; W{ super }; end
20
+ def clear ; W{ super }; end
20
21
 
21
22
  # enum
22
23
  def each(&b) ; R{ super }; end
@@ -80,6 +80,11 @@ module Ccp
80
80
  return h
81
81
  end
82
82
 
83
+ def clear
84
+ tryW("clear")
85
+ @db.clear or tokyo_error!("clear: ")
86
+ end
87
+
83
88
  ######################################################################
84
89
  ### iterator
85
90
 
@@ -4,6 +4,7 @@ module Ccp
4
4
  def execute(cmd)
5
5
  cmd.must.duck!("before") {}
6
6
  super
7
+ ensure
7
8
  cmd.must.duck!("after") {}
8
9
  end
9
10
  end
@@ -1,3 +1,3 @@
1
1
  module Ccp
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
@@ -94,6 +94,18 @@ Ccp::Kvs.each do |klass|
94
94
  end
95
95
  end
96
96
 
97
+ describe "#clear" do
98
+ specify do
99
+ kvs.touch
100
+ kvs.codec! :json
101
+ kvs.write("a"=>1)
102
+ kvs["a"].should == 1
103
+ kvs.clear
104
+ kvs.count.should == 0
105
+ kvs.read.should == {}
106
+ end
107
+ end
108
+
97
109
  describe "#codec!" do
98
110
  specify "return self" do
99
111
  kvs.codec!(:msgpack).should == kvs
@@ -0,0 +1,43 @@
1
+ require "spec_helper"
2
+
3
+ describe Ccp::Receivers::Aroundable do
4
+ class AroundableTestOk < Cmd1
5
+ def execute
6
+ # NOP
7
+ end
8
+ end
9
+
10
+ class AroundableTestNg < Cmd1
11
+ def execute
12
+ raise "some error"
13
+ end
14
+ end
15
+
16
+ let(:options) { {:breadcrumbs => []} }
17
+ let(:program) { raise "program not set" }
18
+ let(:receiver) { Ccp::Receivers::Base.new }
19
+ let(:data) { receiver.data }
20
+
21
+ def execute
22
+ data[:breadcrumbs] = []
23
+ program.execute(:receiver => receiver)
24
+ end
25
+
26
+ describe "#execute" do
27
+ context "(success)" do
28
+ let(:program) { AroundableTestOk }
29
+ it "should call before, after" do
30
+ lambda { execute }.should_not raise_error
31
+ data[:breadcrumbs].should == ["AroundableTestOk#before", "AroundableTestOk#after"]
32
+ end
33
+ end
34
+
35
+ context "(error)" do
36
+ let(:program) { AroundableTestNg }
37
+ it "should call before, after" do
38
+ lambda { execute }.should raise_error("some error")
39
+ data[:breadcrumbs].should == ["AroundableTestNg#before", "AroundableTestNg#after"]
40
+ end
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ccp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-13 00:00:00.000000000 Z
12
+ date: 2013-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -293,6 +293,7 @@ files:
293
293
  - spec/persistent/loadable_spec.rb
294
294
  - spec/persistent/tsv_spec.rb
295
295
  - spec/persistent/versioned_spec.rb
296
+ - spec/receivers/aroundable_spec.rb
296
297
  - spec/receivers/fixture_msgpack_spec.rb
297
298
  - spec/receivers/fixture_save_how_spec.rb
298
299
  - spec/receivers/fixture_save_ignore_logger_spec.rb