couchbase-eraser 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.MIT ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013 LinkedIn
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,48 @@
1
+ Overview
2
+ --------
3
+
4
+ CouchbaseEraser wraps the
5
+ [Couchbase](http://rubydoc.info/gems/couchbase/latest/frames) client, tracks
6
+ every write you perform, and provides a method to delete every key that you
7
+ wrote to.
8
+
9
+ This is useful for testing, where you want to avoid your tests interfering with
10
+ each other by leaving data around in Couchbase.
11
+
12
+ Usage
13
+ -----
14
+
15
+ In your `spec/spec_helper.rb` or similar, assuming you have a class
16
+ `WidgetCache` with a class method `WidgetCache.couchbase` which returns the
17
+ Couchbase client:
18
+
19
+ ```ruby
20
+ require 'couchbase/eraser'
21
+
22
+ class << WidgetCache
23
+ def couchbase_with_erasure
24
+ couchbase_eraser
25
+ end
26
+
27
+ def couchbase_eraser
28
+ @couchbase_eraser ||= Couchbase::Eraser.new(couchbase_without_erasure)
29
+ end
30
+
31
+ alias_method_chain :couchbase, :erasure
32
+ end
33
+
34
+ RSpec.configure do |config|
35
+ config.after(:each) do
36
+ WidgetCache.couchbase_eraser.erase_written_keys
37
+ end
38
+ end
39
+ ```
40
+
41
+ Limitations
42
+ -----------
43
+
44
+ For now the only supported operations are GET, SET and DELETE, although it
45
+ shouldn't be hard to support more methods. (For an operation which
46
+ straightforwardly reads from or writes to a single key, it's a one-line change
47
+ to add support for it. Operations with more complicated semantics, such as
48
+ map-reduce, will be harder to support.)
@@ -0,0 +1,45 @@
1
+ module Couchbase
2
+ class Eraser
3
+ READ_METHODS = %w(
4
+ get
5
+ ).map(&:to_sym)
6
+
7
+ WRITE_METHODS = %w(
8
+ set
9
+ ).map(&:to_sym)
10
+
11
+ attr_reader :client; private :client
12
+
13
+ def initialize(client)
14
+ @client = client
15
+ reset_keys!
16
+ end
17
+
18
+ def erase_written_keys
19
+ @keys.each do |key|
20
+ client.delete key, quiet: true
21
+ end
22
+ reset_keys!
23
+ end
24
+
25
+ ([:delete] + READ_METHODS).each do |meth|
26
+ meth = meth.to_sym
27
+ define_method meth do |key, *args, &block|
28
+ client.send meth, key, *args, &block
29
+ end
30
+ end
31
+
32
+ WRITE_METHODS.each do |meth|
33
+ meth = meth.to_sym
34
+ define_method meth do |key, *args, &block|
35
+ @keys << key
36
+ client.send meth, key, *args, &block
37
+ end
38
+ end
39
+
40
+ private
41
+ def reset_keys!
42
+ @keys = Set.new
43
+ end
44
+ end
45
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path('couchbase/eraser', File.dirname(__FILE__))
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: couchbase-eraser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sam Stokes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: ! 'CouchbaseEraser wraps the Couchbase client, tracks every write you
47
+ perform, and provides a method to delete every key that you wrote to.
48
+
49
+
50
+ This is useful for testing, where you want to avoid your tests interfering with
51
+ each other by leaving data around in Couchbase.
52
+
53
+ '
54
+ email:
55
+ - sstokes@linkedin.com
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - lib/couchbase/eraser.rb
61
+ - lib/couchbase-eraser.rb
62
+ - LICENSE.MIT
63
+ - README.markdown
64
+ homepage: https://github.com/rapportive-oss/couchbase-eraser
65
+ licenses:
66
+ - MIT
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.23
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Wrapper for Couchbase client that deletes your data when you're done with
89
+ it
90
+ test_files: []
91
+ has_rdoc: