couchbase-orm 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/couchbase-orm.gemspec +1 -1
- data/lib/couchbase-orm.rb +2 -4
- data/lib/couchbase-orm/base.rb +9 -17
- data/lib/couchbase-orm/connection.rb +0 -6
- data/lib/couchbase-orm/persistence.rb +7 -26
- data/lib/couchbase-orm/utilities/index.rb +5 -16
- data/lib/couchbase-orm/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30ece0939354be24d837389441c065a99526b79e
|
4
|
+
data.tar.gz: 152e0ab95ae5b843e8c3aeb4d697f863666759b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a00046733b74236cb88e68075b1eecaa6c54a65696daace7847b643c871221647c07aff574d36b011a848142260f17ff54a8489d81c7a14b832603c503005b4
|
7
|
+
data.tar.gz: 92d43d339fb8af9c4d07113d55868d17c766a037d2cf3c7ec04ae5db6b33434df7a6dbf1a27135c66c2d9fc0466287848383e7d8e12be841446592d4389e481e
|
data/couchbase-orm.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.required_ruby_version = '>= 2.1.0'
|
14
14
|
gem.require_paths = ["lib"]
|
15
15
|
|
16
|
-
gem.add_runtime_dependency 'libcouchbase', '~> 0.
|
16
|
+
gem.add_runtime_dependency 'libcouchbase', '~> 0.1'
|
17
17
|
gem.add_runtime_dependency 'activemodel', '~> 5.0'
|
18
18
|
gem.add_runtime_dependency 'radix', '~> 2.2' # converting numbers to and from any base
|
19
19
|
|
data/lib/couchbase-orm.rb
CHANGED
@@ -10,10 +10,8 @@ module CouchbaseOrm
|
|
10
10
|
|
11
11
|
def self.try_load(id)
|
12
12
|
result = nil
|
13
|
-
::
|
14
|
-
|
15
|
-
end
|
16
|
-
|
13
|
+
result = id.respond_to?(:cas) ? id : CouchbaseOrm::Base.bucket.get(id, quiet: true, extended: true)
|
14
|
+
|
17
15
|
if result && result.value.is_a?(Hash) && result.value[:type]
|
18
16
|
ddoc = result.value[:type]
|
19
17
|
::CouchbaseOrm::Base.descendants.each do |model|
|
data/lib/couchbase-orm/base.rb
CHANGED
@@ -52,11 +52,6 @@ module CouchbaseOrm
|
|
52
52
|
@bucket ||= Connection.bucket
|
53
53
|
end
|
54
54
|
|
55
|
-
at_exit do
|
56
|
-
# This will disconnect the database connection
|
57
|
-
@bucket = nil
|
58
|
-
end
|
59
|
-
|
60
55
|
def uuid_generator
|
61
56
|
@uuid_generator ||= IdGenerator
|
62
57
|
end
|
@@ -102,12 +97,8 @@ module CouchbaseOrm
|
|
102
97
|
raise Libcouchbase::Error::EmptyKey, 'no id(s) provided'
|
103
98
|
end
|
104
99
|
|
105
|
-
|
106
|
-
|
107
|
-
records = bucket.get(*ids, **options)
|
108
|
-
end
|
109
|
-
|
110
|
-
records = records.is_a?(Array) ? records : [records]
|
100
|
+
record = bucket.get(*ids, **options)
|
101
|
+
records = record.is_a?(Array) ? record : [record]
|
111
102
|
records.map! { |record|
|
112
103
|
if record
|
113
104
|
self.new(record)
|
@@ -126,11 +117,7 @@ module CouchbaseOrm
|
|
126
117
|
alias_method :[], :find_by_id
|
127
118
|
|
128
119
|
def exists?(id)
|
129
|
-
|
130
|
-
::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
|
131
|
-
val = bucket.get(id, quiet: true).nil?
|
132
|
-
end
|
133
|
-
!val
|
120
|
+
!bucket.get(id, quiet: true).nil?
|
134
121
|
end
|
135
122
|
alias_method :has_key?, :exists?
|
136
123
|
end
|
@@ -280,7 +267,12 @@ module CouchbaseOrm
|
|
280
267
|
#
|
281
268
|
# Returns a boolean.
|
282
269
|
def ==(other)
|
283
|
-
|
270
|
+
case other
|
271
|
+
when self.class
|
272
|
+
hash == other.hash
|
273
|
+
else
|
274
|
+
false
|
275
|
+
end
|
284
276
|
end
|
285
277
|
end
|
286
278
|
end
|
@@ -99,9 +99,7 @@ module CouchbaseOrm
|
|
99
99
|
# The record is simply removed, no callbacks are executed.
|
100
100
|
def delete(with_cas: false, **options)
|
101
101
|
options[:cas] = @__metadata__.cas if with_cas
|
102
|
-
|
103
|
-
self.class.bucket.delete(@__metadata__.key, options)
|
104
|
-
end
|
102
|
+
self.class.bucket.delete(@__metadata__.key, options)
|
105
103
|
|
106
104
|
@__metadata__.key = nil
|
107
105
|
@id = nil
|
@@ -123,9 +121,7 @@ module CouchbaseOrm
|
|
123
121
|
destroy_associations!
|
124
122
|
|
125
123
|
options[:cas] = @__metadata__.cas if with_cas
|
126
|
-
|
127
|
-
self.class.bucket.delete(@__metadata__.key, options)
|
128
|
-
end
|
124
|
+
self.class.bucket.delete(@__metadata__.key, options)
|
129
125
|
|
130
126
|
@__metadata__.key = nil
|
131
127
|
@id = nil
|
@@ -176,10 +172,7 @@ module CouchbaseOrm
|
|
176
172
|
options = {}
|
177
173
|
options[:cas] = @__metadata__.cas if with_cas
|
178
174
|
|
179
|
-
resp =
|
180
|
-
::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
|
181
|
-
resp = self.class.bucket.replace(_id, @__attributes__, **options)
|
182
|
-
end
|
175
|
+
resp = self.class.bucket.replace(_id, @__attributes__, **options)
|
183
176
|
|
184
177
|
# Ensure the model is up to date
|
185
178
|
@__metadata__.key = resp.key
|
@@ -196,10 +189,7 @@ module CouchbaseOrm
|
|
196
189
|
key = @__metadata__.key
|
197
190
|
raise "unable to reload, model not persisted" unless key
|
198
191
|
|
199
|
-
resp =
|
200
|
-
::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
|
201
|
-
resp = self.class.bucket.get(key, quiet: false, extended: true)
|
202
|
-
end
|
192
|
+
resp = self.class.bucket.get(key, quiet: false, extended: true)
|
203
193
|
@__attributes__ = ::ActiveSupport::HashWithIndifferentAccess.new(resp.value)
|
204
194
|
@__metadata__.key = resp.key
|
205
195
|
@__metadata__.cas = resp.cas
|
@@ -211,10 +201,7 @@ module CouchbaseOrm
|
|
211
201
|
|
212
202
|
# Updates the TTL of the document
|
213
203
|
def touch(**options)
|
214
|
-
res =
|
215
|
-
::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
|
216
|
-
res = self.class.bucket.touch(@__metadata__.key, async: false, **options)
|
217
|
-
end
|
204
|
+
res = self.class.bucket.touch(@__metadata__.key, async: false, **options)
|
218
205
|
@__metadata__.cas = resp.cas
|
219
206
|
self
|
220
207
|
end
|
@@ -236,10 +223,7 @@ module CouchbaseOrm
|
|
236
223
|
_id = @__metadata__.key
|
237
224
|
options[:cas] = @__metadata__.cas if with_cas
|
238
225
|
|
239
|
-
resp =
|
240
|
-
::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
|
241
|
-
resp = self.class.bucket.replace(_id, @__attributes__, **options)
|
242
|
-
end
|
226
|
+
resp = self.class.bucket.replace(_id, @__attributes__, **options)
|
243
227
|
|
244
228
|
# Ensure the model is up to date
|
245
229
|
@__metadata__.key = resp.key
|
@@ -261,10 +245,7 @@ module CouchbaseOrm
|
|
261
245
|
@__attributes__.delete(:id)
|
262
246
|
|
263
247
|
_id = @id || self.class.uuid_generator.next(self)
|
264
|
-
resp =
|
265
|
-
::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
|
266
|
-
resp = self.class.bucket.add(_id, @__attributes__, **options)
|
267
|
-
end
|
248
|
+
resp = self.class.bucket.add(_id, @__attributes__, **options)
|
268
249
|
|
269
250
|
# Ensure the model is up to date
|
270
251
|
@__metadata__.key = resp.key
|
@@ -50,18 +50,13 @@ module CouchbaseOrm
|
|
50
50
|
# use the bucket key as an index - lookup records by attr values
|
51
51
|
define_singleton_method(find_by_method) do |*values|
|
52
52
|
key = self.send(class_bucket_key_method, *values)
|
53
|
-
id
|
54
|
-
::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
|
55
|
-
id = self.bucket.get(key, quiet: true)
|
56
|
-
end
|
53
|
+
id = self.bucket.get(key, quiet: true)
|
57
54
|
if id
|
58
55
|
mod = self.find_by_id(id)
|
59
56
|
return mod if mod
|
60
57
|
|
61
58
|
# Clean up record if the id doesn't exist
|
62
|
-
|
63
|
-
self.bucket.delete(key, quiet: true)
|
64
|
-
end
|
59
|
+
self.bucket.delete(key, quiet: true)
|
65
60
|
end
|
66
61
|
|
67
62
|
nil
|
@@ -103,14 +98,10 @@ module CouchbaseOrm
|
|
103
98
|
# new one. the id of the current record is used as the key's value.
|
104
99
|
after_save do |record|
|
105
100
|
original_key = instance_variable_get(original_bucket_key_var)
|
106
|
-
|
107
|
-
record.class.bucket.delete(original_key, quiet: true) if original_key
|
108
|
-
end
|
101
|
+
record.class.bucket.delete(original_key, quiet: true) if original_key
|
109
102
|
|
110
103
|
unless presence == false && attrs.length == 1 && record[attrs[0]].nil?
|
111
|
-
|
112
|
-
record.class.bucket.set(record.send(bucket_key_method), record.id, plain: true)
|
113
|
-
end
|
104
|
+
record.class.bucket.set(record.send(bucket_key_method), record.id, plain: true)
|
114
105
|
end
|
115
106
|
instance_variable_set(original_bucket_key_var, nil)
|
116
107
|
end
|
@@ -118,9 +109,7 @@ module CouchbaseOrm
|
|
118
109
|
# cleanup by removing the bucket key before the record is deleted
|
119
110
|
# TODO: handle unpersisted, modified component values
|
120
111
|
before_destroy do |record|
|
121
|
-
|
122
|
-
record.class.bucket.delete(record.send(bucket_key_method), quiet: true)
|
123
|
-
end
|
112
|
+
record.class.bucket.delete(record.send(bucket_key_method), quiet: true)
|
124
113
|
true
|
125
114
|
end
|
126
115
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couchbase-orm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen von Takach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libcouchbase
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activemodel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
171
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
172
|
+
rubygems_version: 2.6.10
|
173
173
|
signing_key:
|
174
174
|
specification_version: 4
|
175
175
|
summary: Couchbase ORM for Rails
|