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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6b544f90684482165751da680f83f674fd3241a
4
- data.tar.gz: 94f1a789ec55e715ebdcd11bd5ae1f823f760934
3
+ metadata.gz: 30ece0939354be24d837389441c065a99526b79e
4
+ data.tar.gz: 152e0ab95ae5b843e8c3aeb4d697f863666759b2
5
5
  SHA512:
6
- metadata.gz: 9e61eaa42f447b675ee46a6853a3329d1e25ee397c1cd36d4fec588c187c4f2d8a6963bc94c37c429d8e05ea6cbfcdd86e56668d2680ddb04528e299d06e3f75
7
- data.tar.gz: a77601b7fa9b369a3beb0d214d0e736a9c7691cd6341585791cc1e49d0e9683d3af91228954923a84d5bafe2050afab12c49f7e996a00b141ffb6a631d427bfb
6
+ metadata.gz: 3a00046733b74236cb88e68075b1eecaa6c54a65696daace7847b643c871221647c07aff574d36b011a848142260f17ff54a8489d81c7a14b832603c503005b4
7
+ data.tar.gz: 92d43d339fb8af9c4d07113d55868d17c766a037d2cf3c7ec04ae5db6b33434df7a6dbf1a27135c66c2d9fc0466287848383e7d8e12be841446592d4389e481e
@@ -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.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
- ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
14
- result = id.respond_to?(:cas) ? id : CouchbaseOrm::Base.bucket.get(id, quiet: true, extended: true)
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|
@@ -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
- records = nil
106
- ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
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
- val = false
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
- hash == other.hash
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
@@ -12,11 +12,5 @@ module CouchbaseOrm
12
12
  def self.bucket
13
13
  @bucket ||= ::Libcouchbase::Bucket.new(**@options)
14
14
  end
15
-
16
- # This will disconnect the database connection,
17
- # allowing the application to exit
18
- at_exit do
19
- @bucket = nil
20
- end
21
15
  end
22
16
  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
- ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
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
- ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
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 = nil
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 = nil
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 = nil
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 = nil
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 = nil
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 = nil
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
- ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
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
- ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
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
- ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
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
- ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true, encoding: ASCII-8BIT
2
2
 
3
3
  module CouchbaseOrm
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.0'
5
5
  end
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.1.2
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: 2016-12-08 00:00:00.000000000 Z
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.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.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.5.1
172
+ rubygems_version: 2.6.10
173
173
  signing_key:
174
174
  specification_version: 4
175
175
  summary: Couchbase ORM for Rails