adapter-couch 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ gemspec
3
+
4
+ group(:development) do
5
+ gem 'rake'
6
+ gem 'rspec', '~> 2.3'
7
+ gem 'log_buddy', '~> 0.5.0'
8
+ gem 'timecop', '~> 0.3.5'
9
+ gem 'i18n', '0.5.0'
10
+ gem 'activesupport', '~> 3', :require => 'active_support'
11
+
12
+ gem 'ruby-debug', :platform => :ruby_18
13
+ gem 'ruby-debug19', :platform => :ruby_19, :require => 'ruby-debug'
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ adapter-couch (0.1.1)
5
+ adapter (~> 0.5.1)
6
+ couchrest (~> 1.1.0.pre2)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activesupport (3.0.3)
12
+ adapter (0.5.2)
13
+ archive-tar-minitar (0.5.2)
14
+ columnize (0.3.2)
15
+ couchrest (1.1.0.pre2)
16
+ json (~> 1.5.1)
17
+ mime-types (~> 1.15)
18
+ rest-client (~> 1.6.1)
19
+ diff-lcs (1.1.2)
20
+ i18n (0.5.0)
21
+ json (1.5.1)
22
+ linecache (0.43)
23
+ linecache19 (0.5.11)
24
+ ruby_core_source (>= 0.1.4)
25
+ log_buddy (0.5.0)
26
+ mime-types (1.16)
27
+ rake (0.8.7)
28
+ rest-client (1.6.1)
29
+ mime-types (>= 1.16)
30
+ rspec (2.4.0)
31
+ rspec-core (~> 2.4.0)
32
+ rspec-expectations (~> 2.4.0)
33
+ rspec-mocks (~> 2.4.0)
34
+ rspec-core (2.4.0)
35
+ rspec-expectations (2.4.0)
36
+ diff-lcs (~> 1.1.2)
37
+ rspec-mocks (2.4.0)
38
+ ruby-debug (0.10.4)
39
+ columnize (>= 0.1)
40
+ ruby-debug-base (~> 0.10.4.0)
41
+ ruby-debug-base (0.10.4)
42
+ linecache (>= 0.3)
43
+ ruby-debug-base19 (0.11.24)
44
+ columnize (>= 0.3.1)
45
+ linecache19 (>= 0.5.11)
46
+ ruby_core_source (>= 0.1.4)
47
+ ruby-debug19 (0.11.6)
48
+ columnize (>= 0.3.1)
49
+ linecache19 (>= 0.5.11)
50
+ ruby-debug-base19 (>= 0.11.19)
51
+ ruby_core_source (0.1.4)
52
+ archive-tar-minitar (>= 0.5.2)
53
+ timecop (0.3.5)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ activesupport (~> 3)
60
+ adapter-couch!
61
+ i18n (= 0.5.0)
62
+ log_buddy (~> 0.5.0)
63
+ rake
64
+ rspec (~> 2.3)
65
+ ruby-debug
66
+ ruby-debug19
67
+ timecop (~> 0.3.5)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 John Nunemaker
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,35 @@
1
+ = adapter-couch
2
+
3
+ CouchDB adapter for adapter gem.
4
+
5
+ require 'adapter/couch'
6
+
7
+ client = CouchRest.database!("http://127.0.0.1:5984/adapter-couch-test")
8
+ adapter = Adapter[:couch].new(client)
9
+ adapter.clear
10
+
11
+ adapter.write('foo', 'bar')
12
+ puts 'Should be bar: ' + adapter.read('foo').inspect
13
+
14
+ adapter.delete('foo')
15
+ puts 'Should be nil: ' + adapter.read('foo').inspect
16
+
17
+ adapter.write('foo', 'bar')
18
+ adapter.clear
19
+ puts 'Should be nil: ' + adapter.read('foo').inspect
20
+
21
+ puts 'Should be bar: ' + adapter.fetch('foo', 'bar')
22
+
23
+ See examples/ or specs/ for more usage.
24
+
25
+ ==
26
+
27
+ This is forked from https://github.com/jnunemaker/adapter-mongo
28
+
29
+ == Note on Patches/Pull Requests
30
+
31
+ * Fork the project.
32
+ * Make your feature addition or bug fix.
33
+ * Add tests for it. This is important so we don't break it in a future version unintentionally.
34
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine, but bump version in a commit by itself so we can ignore when we pull)
35
+ * Send us a pull request. Bonus points for topic branches.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "adapter/couch/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "adapter-couch"
7
+ s.version = Adapter::Couch::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Pelle Braendgaard"]
10
+ s.email = ["pelle@stakeventures.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Adapter for couch}
13
+ s.description = %q{Adapter for couch}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency 'adapter', '~> 0.5.1'
21
+ s.add_dependency 'couchrest', '~> 1.1.0.pre2'
22
+ end
data/examples/couch.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'pathname'
3
+
4
+ root_path = Pathname(__FILE__).dirname.join('..').expand_path
5
+ lib_path = root_path.join('lib')
6
+ $:.unshift(lib_path)
7
+
8
+ require 'adapter/couch'
9
+
10
+ client = Couch::Connection.new.db('adapter')['testing']
11
+ adapter = Adapter[:couch].new(client)
12
+ adapter.clear
13
+
14
+ adapter.write('foo', 'bar')
15
+ puts 'Should be bar: ' + adapter.read('foo').inspect
16
+
17
+ adapter.delete('foo')
18
+ puts 'Should be nil: ' + adapter.read('foo').inspect
19
+
20
+ adapter.write('foo', 'bar')
21
+ adapter.clear
22
+ puts 'Should be nil: ' + adapter.read('foo').inspect
23
+
24
+ puts 'Should be bar: ' + adapter.fetch('foo', 'bar')
@@ -0,0 +1,5 @@
1
+ module Adapter
2
+ module Couch
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,49 @@
1
+ require 'adapter'
2
+ require 'couchrest'
3
+
4
+ module Adapter
5
+ module Couch
6
+ NonHashValueKeyName = 'nh_value'
7
+
8
+ def read(key)
9
+ begin
10
+ if doc = client.get(key_for(key))
11
+ decode(doc)
12
+ end
13
+ rescue RestClient::ResourceNotFound => e
14
+ nil
15
+ end
16
+ end
17
+
18
+ def write(key, value)
19
+ doc = client.save_doc({"_id" => key_for(key)}.merge(encode(value)))
20
+ doc
21
+ end
22
+
23
+ def delete(key)
24
+ begin
25
+ doc = client.get(key_for(key))
26
+ client.delete_doc(doc)
27
+ decode(doc)
28
+ rescue RestClient::ResourceNotFound => e
29
+ nil
30
+ end
31
+ end
32
+
33
+ def clear
34
+ client.recreate!
35
+ end
36
+
37
+ def encode(value)
38
+ value.is_a?(Hash) ? value : {NonHashValueKeyName => value}
39
+ end
40
+
41
+ def decode(value)
42
+ return if value.nil?
43
+ value.key?(NonHashValueKeyName) ? value[NonHashValueKeyName] : value
44
+ end
45
+
46
+ end
47
+ end
48
+
49
+ Adapter.define(:couch, Adapter::Couch)
@@ -0,0 +1 @@
1
+ require 'adapter/couch'
data/log/test.log ADDED
@@ -0,0 +1,101 @@
1
+ # Logfile created on Thu Feb 03 09:08:05 -0500 2011 by logger.rb
2
+ D, [2011-02-03T09:10:58.204661 #18222] DEBUG -- : key = "key"
3
+
4
+ D, [2011-02-03T09:10:58.209325 #18222] DEBUG -- : key = "key"
5
+
6
+ D, [2011-02-03T09:10:58.211837 #18222] DEBUG -- : key = "key"
7
+
8
+ D, [2011-02-03T09:10:58.214308 #18222] DEBUG -- : key = "key"
9
+
10
+ D, [2011-02-03T09:10:58.216590 #18222] DEBUG -- : key = "key"
11
+
12
+ D, [2011-02-03T09:10:58.218848 #18222] DEBUG -- : key = "key"
13
+
14
+ D, [2011-02-03T09:10:58.221382 #18222] DEBUG -- : key = "key"
15
+
16
+ D, [2011-02-03T09:10:58.224140 #18222] DEBUG -- : key = "key"
17
+
18
+ D, [2011-02-03T09:10:58.226556 #18222] DEBUG -- : key = "key"
19
+
20
+ D, [2011-02-03T09:10:58.229142 #18222] DEBUG -- : key = "key"
21
+
22
+ D, [2011-02-03T09:10:58.231546 #18222] DEBUG -- : key = "key"
23
+
24
+ D, [2011-02-03T09:10:58.233860 #18222] DEBUG -- : key = "key"
25
+
26
+ D, [2011-02-03T09:10:58.236431 #18222] DEBUG -- : key = "key"
27
+
28
+ D, [2011-02-03T09:10:58.242707 #18222] DEBUG -- : key = "key"
29
+
30
+ D, [2011-02-03T09:10:58.245981 #18222] DEBUG -- : key = "key"
31
+
32
+ D, [2011-02-03T09:10:58.249845 #18222] DEBUG -- : key = #<struct #<Class:0x10108ca80> foo=:bar>
33
+
34
+ D, [2011-02-03T09:10:58.253667 #18222] DEBUG -- : key = #<struct #<Class:0x101084a60> foo=:bar>
35
+
36
+ D, [2011-02-03T09:10:58.263219 #18222] DEBUG -- : key = #<struct #<Class:0x101070ee8> foo=:bar>
37
+
38
+ D, [2011-02-03T09:10:58.266937 #18222] DEBUG -- : key = #<struct #<Class:0x101068ba8> foo=:bar>
39
+
40
+ D, [2011-02-03T09:11:55.657172 #18355] DEBUG -- : key = "key"
41
+
42
+ D, [2011-02-03T09:11:55.657825 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>{"foo"=>:bar}}
43
+
44
+ D, [2011-02-03T09:11:55.663921 #18355] DEBUG -- : key = "key"
45
+
46
+ D, [2011-02-03T09:11:55.666827 #18355] DEBUG -- : key = "key"
47
+
48
+ D, [2011-02-03T09:11:55.667326 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>"value"}
49
+
50
+ D, [2011-02-03T09:11:55.670437 #18355] DEBUG -- : key = "key"
51
+
52
+ D, [2011-02-03T09:11:55.671005 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>"value"}
53
+
54
+ D, [2011-02-03T09:11:55.673365 #18355] DEBUG -- : key = "key"
55
+
56
+ D, [2011-02-03T09:11:55.673866 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>{"foo"=>:bar}}
57
+
58
+ D, [2011-02-03T09:11:55.676317 #18355] DEBUG -- : key = "key"
59
+
60
+ D, [2011-02-03T09:11:55.679298 #18355] DEBUG -- : key = "key"
61
+
62
+ D, [2011-02-03T09:11:55.679806 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>"value"}
63
+
64
+ D, [2011-02-03T09:11:55.682394 #18355] DEBUG -- : key = "key"
65
+
66
+ D, [2011-02-03T09:11:55.682914 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>"value"}
67
+
68
+ D, [2011-02-03T09:11:55.685868 #18355] DEBUG -- : key = "key"
69
+
70
+ D, [2011-02-03T09:11:55.689148 #18355] DEBUG -- : key = "key"
71
+
72
+ D, [2011-02-03T09:11:55.690046 #18355] DEBUG -- : key = "key2"
73
+
74
+ D, [2011-02-03T09:11:55.693727 #18355] DEBUG -- : key = "key"
75
+
76
+ D, [2011-02-03T09:11:55.694439 #18355] DEBUG -- : key = "key"
77
+
78
+ D, [2011-02-03T09:11:55.697517 #18355] DEBUG -- : key = "key"
79
+
80
+ D, [2011-02-03T09:11:55.698093 #18355] DEBUG -- : key = "key"
81
+
82
+ D, [2011-02-03T09:11:55.700749 #18355] DEBUG -- : key = "key"
83
+
84
+ D, [2011-02-03T09:11:55.701243 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>"value"}
85
+
86
+ D, [2011-02-03T09:11:55.703567 #18355] DEBUG -- : key = "key"
87
+
88
+ D, [2011-02-03T09:11:55.704074 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>"value2"}
89
+
90
+ D, [2011-02-03T09:11:55.708152 #18355] DEBUG -- : key = "key"
91
+
92
+ D, [2011-02-03T09:11:55.708842 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>"value"}
93
+
94
+ D, [2011-02-03T09:11:55.712637 #18355] DEBUG -- : key = #<struct #<Class:0x10103a5a0> foo=:bar>
95
+
96
+ D, [2011-02-03T09:11:55.716432 #18355] DEBUG -- : key = #<struct #<Class:0x101032f58> foo=:bar>
97
+
98
+ D, [2011-02-03T09:11:55.725740 #18355] DEBUG -- : key = #<struct #<Class:0x10101dec8> foo=:bar>
99
+
100
+ D, [2011-02-03T09:11:55.729651 #18355] DEBUG -- : key = #<struct #<Class:0x1010162b8> foo=:bar>
101
+
@@ -0,0 +1,21 @@
1
+ require 'helper'
2
+ require 'couchrest'
3
+
4
+ describe "Couch adapter" do
5
+ before do
6
+ @client = CouchRest.database!("http://127.0.0.1:5984/adapter-couch-test")
7
+ @adapter = Adapter[:couch].new(@client)
8
+ @adapter.clear
9
+ end
10
+
11
+ let(:adapter) { @adapter }
12
+ let(:client) { @client }
13
+
14
+ it_should_behave_like 'a couch adapter'
15
+
16
+ it "stores hashes right in document" do
17
+ doc = adapter.write('foo', 'steak' => 'bacon')
18
+ client.get('foo').should == {'_id' => 'foo', '_rev' => doc['rev'], 'steak' => 'bacon'}
19
+ end
20
+
21
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,38 @@
1
+ $:.unshift(File.expand_path('../../lib', __FILE__))
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+
6
+ Bundler.require(:default, :development)
7
+
8
+ require 'pathname'
9
+ require 'logger'
10
+
11
+ root_path = Pathname(__FILE__).dirname.join('..').expand_path
12
+ lib_path = root_path.join('lib')
13
+ log_path = root_path.join('log')
14
+ log_path.mkpath
15
+
16
+ require 'adapter/spec/an_adapter'
17
+ require 'adapter/spec/types'
18
+
19
+ require 'adapter-couch'
20
+
21
+ shared_examples_for "a couch adapter" do
22
+ it_should_behave_like 'an adapter'
23
+
24
+ Adapter::Spec::Types.each do |type, (key, key2)|
25
+ it "writes Object values to keys that are #{type}s like a Hash" do
26
+ v = adapter.write(key, {:foo => :bar})
27
+ # couch knows hashes
28
+ adapter[key].should == {'_id' => 'key', 'foo' => 'bar', '_rev' => v['rev']}
29
+ end
30
+ end
31
+ end
32
+
33
+ logger = Logger.new(log_path.join('test.log'))
34
+ LogBuddy.init(:logger => logger)
35
+
36
+ Rspec.configure do |c|
37
+
38
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adapter-couch
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.1
6
+ platform: ruby
7
+ authors:
8
+ - Pelle Braendgaard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-21 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: adapter
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 0.5.1
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: couchrest
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 1.1.0.pre2
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description: Adapter for couch
39
+ email:
40
+ - pelle@stakeventures.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE
52
+ - README.rdoc
53
+ - Rakefile
54
+ - adapter-couch.gemspec
55
+ - examples/couch.rb
56
+ - lib/adapter-couch.rb
57
+ - lib/adapter/couch.rb
58
+ - lib/adapter/couch/version.rb
59
+ - log/test.log
60
+ - spec/couch_spec.rb
61
+ - spec/helper.rb
62
+ has_rdoc: true
63
+ homepage: ""
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options: []
68
+
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
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.6.2
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Adapter for couch
90
+ test_files:
91
+ - spec/couch_spec.rb
92
+ - spec/helper.rb