couchbase-documentstore 0.0.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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/couchbase_document_store.gemspec +22 -0
- data/lib/couchbase_document_store/version.rb +3 -0
- data/lib/couchbase_document_store.rb +188 -0
- metadata +87 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jasdeep Jaitla
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# CouchbaseDocumentStore
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'couchbase_document_store'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install couchbase_document_store
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'couchbase_document_store/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "couchbase-documentstore"
|
8
|
+
gem.version = CouchbaseDocumentStore::VERSION
|
9
|
+
gem.authors = ["Jasdeep Jaitla"]
|
10
|
+
gem.email = ["jasdeep@scalabl3.com"]
|
11
|
+
gem.description = %q{A Convenient Wrapper for the Couchbase gem, uses Map gem and }
|
12
|
+
gem.summary = %q{You simply use the Couchbase gem, or you can use this wrapper that encapsulates the gem and adds some subjective conveniences. }
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.add_dependency('couchbase-settings', '>= 0.0.3')
|
16
|
+
gem.add_dependency('couchbase', '>= 1.2.0.z.beta3')
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split($/)
|
19
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
|
+
gem.require_paths = ["lib"]
|
22
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require 'couchbase'
|
2
|
+
require 'map'
|
3
|
+
require 'couchbase-settings'
|
4
|
+
require "couchbase_document_store/version"
|
5
|
+
|
6
|
+
module CouchbaseDocumentStore
|
7
|
+
|
8
|
+
|
9
|
+
setting_hash = {}
|
10
|
+
if (CouchbaseSettings.couchbase_servers && !CouchbaseSettings.servers.empty?)
|
11
|
+
setting_hash[:node_list] = CouchbaseSettings.servers
|
12
|
+
elsif (CouchbaseSettings.server && !CouchbaseSettings.server.empty?)
|
13
|
+
setting_hash[:hostname] = CouchbaseSettings.server
|
14
|
+
else
|
15
|
+
raise ArgumentError, "You didn't set a Couchbase Server in your /config/couchbase.yml file!"
|
16
|
+
end
|
17
|
+
setting_hash[:pool] = "default"
|
18
|
+
setting_hash[:bucket] = CouchbaseSettings.couchbase_bucket
|
19
|
+
setting_hash[:port] = 8091
|
20
|
+
|
21
|
+
if (CouchbaseSettings.couchbase_password && !CouchbaseSettings.couchbase_password.empty?)
|
22
|
+
setting_hash[:username] = CouchbaseSettings.bucket
|
23
|
+
setting_hash[:password] = CouchbaseSettings.password
|
24
|
+
end
|
25
|
+
|
26
|
+
CB = Couchbase.connect(setting_hash)
|
27
|
+
|
28
|
+
#### INSTANCE METHODS
|
29
|
+
|
30
|
+
# Check if a key/document exists
|
31
|
+
def document_exists?(key)
|
32
|
+
return nil unless key
|
33
|
+
CouchbaseDocumentStore.document_exists?(key)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Initialize a document, if it doesn't exist, create it, if it exists, ignore the call
|
37
|
+
def initialize_document(key, value, args={})
|
38
|
+
return nil unless key
|
39
|
+
CouchbaseDocumentStore.initialize_document(key, value, args)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Create a new document (Couchbase#add)
|
43
|
+
def create_document(key, value, args={})
|
44
|
+
return nil unless key
|
45
|
+
CouchbaseDocumentStore.create_document(key, value, args) # => if !quiet, Generates Couchbase::Error::KeyExists if key already exists
|
46
|
+
end
|
47
|
+
|
48
|
+
# Replace a new document (Couchbase#replace), throws Couchbase::Error:: if it doesn't exist
|
49
|
+
def replace_document(key, value, args = {})
|
50
|
+
return nil unless key
|
51
|
+
CouchbaseDocumentStore.replace_document(key, value, args)
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
def get_document(key, args = {})
|
56
|
+
return nil unless key
|
57
|
+
CouchbaseDocumentStore.get_document(key, args)
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_documents(keys = [], args = {})
|
61
|
+
return nil unless keys || keys.empty?
|
62
|
+
CouchbaseDocumentStore.get_documents(keys, args)
|
63
|
+
end
|
64
|
+
|
65
|
+
def delete_document(key, args={})
|
66
|
+
return nil unless key
|
67
|
+
CouchbaseDocumentStore.delete_document(key, args)
|
68
|
+
end
|
69
|
+
|
70
|
+
# @param args :amount => Fixnum||Integer, increases by that
|
71
|
+
def increase_atomic_count(key, args={})
|
72
|
+
return nil unless key
|
73
|
+
CouchbaseDocumentStore.increase_atomic_count(key, args)
|
74
|
+
end
|
75
|
+
|
76
|
+
def decrease_atomic_count(key, args={})
|
77
|
+
return nil unless key
|
78
|
+
CouchbaseDocumentStore.decrease_atomic_count(key, args)
|
79
|
+
end
|
80
|
+
|
81
|
+
# preferred way is to use create/replace to make sure there are no collisions
|
82
|
+
def force_set_document(key, value, args={})
|
83
|
+
return nil unless key
|
84
|
+
CouchbaseDocumentStore.force_set_document(key, value, args)
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
# end Instance Methods
|
90
|
+
#####################################################################
|
91
|
+
#### CLASS METHODS
|
92
|
+
|
93
|
+
class << self
|
94
|
+
|
95
|
+
def delete_all_documents!
|
96
|
+
CB.flush
|
97
|
+
end
|
98
|
+
|
99
|
+
def document_exists?(key)
|
100
|
+
return nil unless key
|
101
|
+
|
102
|
+
# Save quiet setting
|
103
|
+
tmp = CB.quiet
|
104
|
+
|
105
|
+
# Set quiet to be sure
|
106
|
+
CB.quiet = true
|
107
|
+
|
108
|
+
doc = CB.get(key)
|
109
|
+
|
110
|
+
# Restore quiet setting
|
111
|
+
CB.quiet = tmp
|
112
|
+
|
113
|
+
!doc.nil?
|
114
|
+
end
|
115
|
+
|
116
|
+
def initialize_document(key, value, args={})
|
117
|
+
return nil unless key
|
118
|
+
CB.quiet = true
|
119
|
+
doc = DocumentStore.get_document( key )
|
120
|
+
(value.is_a?(Fixnum) || value.is_a?(Integer) ? CB.set( key, value ) : CB.add( key, value )) unless doc
|
121
|
+
end
|
122
|
+
|
123
|
+
def create_document(key, value, args={})
|
124
|
+
return nil unless key
|
125
|
+
CB.quiet = args[:quiet] || true
|
126
|
+
CB.add(key, value, args) # => if !quiet, Generates Couchbase::Error::KeyExists if key already exists
|
127
|
+
end
|
128
|
+
|
129
|
+
def replace_document(key, value, args = {})
|
130
|
+
return nil unless key
|
131
|
+
CB.quiet = args[:quiet] || true
|
132
|
+
CB.replace(key, value) # => if !quiet, Generates Couchbase::Error::NotFound if key doesn't exist
|
133
|
+
end
|
134
|
+
|
135
|
+
def get_document(key, args = {})
|
136
|
+
return nil unless key
|
137
|
+
CB.quiet = args[:quiet] || true
|
138
|
+
doc = CB.get(key, args)
|
139
|
+
doc.is_a?(Hash) ? Map.new(doc) : doc
|
140
|
+
end
|
141
|
+
|
142
|
+
def get_documents(keys = [], args = {})
|
143
|
+
return nil unless keys || keys.empty?
|
144
|
+
values = CB.get(keys, args)
|
145
|
+
|
146
|
+
if values.is_a? Hash
|
147
|
+
tmp = []
|
148
|
+
tmp[0] = values
|
149
|
+
values = tmp
|
150
|
+
end
|
151
|
+
# convert hashes to Map (subclass of Hash with *better* indifferent access)
|
152
|
+
values.each_with_index do |v, i|
|
153
|
+
values[i] = Map.new(v) if v.is_a? Hash
|
154
|
+
end
|
155
|
+
|
156
|
+
values
|
157
|
+
end
|
158
|
+
|
159
|
+
def delete_document(key, args={})
|
160
|
+
return nil unless key
|
161
|
+
CB.quiet = args[:quiet] || true
|
162
|
+
CB.delete(key)
|
163
|
+
end
|
164
|
+
|
165
|
+
def increase_atomic_count(key, args={} )
|
166
|
+
return nil unless key
|
167
|
+
CB.quiet = args[:quiet] || true
|
168
|
+
CB.incr(key, args[:amount] || 1)
|
169
|
+
end
|
170
|
+
|
171
|
+
def decrease_atomic_count(key, args={})
|
172
|
+
return nil unless key
|
173
|
+
CB.quiet = args[:quiet] || true
|
174
|
+
CB.decr(key, args[:amount] || 1)
|
175
|
+
end
|
176
|
+
|
177
|
+
# preferred way is to use create/replace instead of this to make sure there are no collisions
|
178
|
+
def force_set_document(key, value, args={})
|
179
|
+
return nil unless key
|
180
|
+
CB.quiet = args[:quiet] || true
|
181
|
+
CB.set(key, value, args)
|
182
|
+
end
|
183
|
+
|
184
|
+
end# end ClassMethods
|
185
|
+
|
186
|
+
#####################################################################
|
187
|
+
|
188
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: couchbase-documentstore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jasdeep Jaitla
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: couchbase-settings
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.0.3
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: couchbase
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.2.0.z.beta3
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.2.0.z.beta3
|
46
|
+
description: ! 'A Convenient Wrapper for the Couchbase gem, uses Map gem and '
|
47
|
+
email:
|
48
|
+
- jasdeep@scalabl3.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- couchbase_document_store.gemspec
|
59
|
+
- lib/couchbase_document_store.rb
|
60
|
+
- lib/couchbase_document_store/version.rb
|
61
|
+
homepage: ''
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.24
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: You simply use the Couchbase gem, or you can use this wrapper that encapsulates
|
85
|
+
the gem and adds some subjective conveniences.
|
86
|
+
test_files: []
|
87
|
+
has_rdoc:
|