ree_lib 1.0.29 → 1.0.30

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
  SHA256:
3
- metadata.gz: 84e4aade5b4eaae42f95c7664db6dd35ea318caf734d2890482d8e6d8fec060a
4
- data.tar.gz: 65969441395458b1520c85e1f71dc610e8d2787a1c2cdcc493477eff93c0fa9a
3
+ metadata.gz: '0384a60b8e6da77137b281c223ae80df078ad10389876fb719bd6eb7264f305c'
4
+ data.tar.gz: 3771e23d3f69dbb9ba8ff56375b35ee039b92c2132e0398912e32677754f444b
5
5
  SHA512:
6
- metadata.gz: a486a292e460edfd1ffb3304d7168ae8f5c9c615c6ae2b32dce08fa661f76f081b9082faa35b5077b43dc28fa0aa39dfb9eb7917fada4736e94cf7c0bbbc2260
7
- data.tar.gz: 6582341e1519c1e06261d1c1e8faa85106e26c12ea4afe7f2a6788fcbf5d19f2c14c39e32b3f29e4ffa7c1bceba052608cbc5d9fdd39245ca09dbcf031dcd12b
6
+ metadata.gz: b0e8d42f124e6252ce81fc64a7980c22c85e252ebdcedb5130fcaa53fda721d80c87804e33926251e5da9b753389593252309e5c09a9df4a769399084b0c158d
7
+ data.tar.gz: a8c6acc47b934e848ef7a98ad579b114cd8988bb78872ef5f2c616638e1e6cbe2d64a5618d6efd8fd5dd1ee1000397bab178fe16948617dff574cfa594eb3cf8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.29)
4
+ ree_lib (1.0.30)
5
5
  binding_of_caller (~> 1.0.0)
6
6
  i18n (~> 1.12.0)
7
7
  loofah (~> 2.18.0)
@@ -36,9 +36,9 @@ GEM
36
36
  crass (~> 1.0.2)
37
37
  nokogiri (>= 1.5.9)
38
38
  msgpack (1.6.0)
39
- nokogiri (1.14.0-x86_64-darwin)
39
+ nokogiri (1.14.1-x86_64-darwin)
40
40
  racc (~> 1.4)
41
- nokogiri (1.14.0-x86_64-linux)
41
+ nokogiri (1.14.1-x86_64-linux)
42
42
  racc (~> 1.4)
43
43
  oj (3.13.23)
44
44
  pg (1.4.5)
@@ -46,7 +46,7 @@ GEM
46
46
  racc (1.6.2)
47
47
  rainbow (3.1.1)
48
48
  rake (13.0.6)
49
- ree (1.0.18)
49
+ ree (1.0.22)
50
50
  commander (~> 4.6.0)
51
51
  rexml (3.2.5)
52
52
  rollbar (3.3.3)
@@ -110,29 +110,20 @@ module ReeDao
110
110
  nil
111
111
  end
112
112
 
113
- def update(entity)
114
- if opts[:schema_mapper]
115
- raw = opts[:schema_mapper].db_dump(entity)
116
- raw = extract_changes(entity, raw)
117
-
118
- unless raw.empty?
119
- update_persistence_state(entity, raw)
120
- key_condition = prepare_key_condition_from_entity(entity)
121
- where(key_condition).__original_update(raw)
122
- end
113
+ def update(hash_or_entity)
114
+ return __original_update(hash_or_entity) if !opts[:schema_mapper]
115
+ return __original_update(hash_or_entity) if hash_or_entity.is_a?(Hash)
123
116
 
124
- entity
125
- else
126
- __original_update(entity)
127
- end
128
- end
117
+ raw = opts[:schema_mapper].db_dump(hash_or_entity)
118
+ raw = extract_changes(hash_or_entity, raw)
129
119
 
130
- def update_where(conditions)
131
- __original_update(conditions)
132
- end
120
+ unless raw.empty?
121
+ update_persistence_state(hash_or_entity, raw)
122
+ key_condition = prepare_key_condition_from_entity(hash_or_entity)
123
+ where(key_condition).__original_update(raw)
124
+ end
133
125
 
134
- def delete_where(conditions)
135
- __original_delete(conditions)
126
+ hash_or_entity
136
127
  end
137
128
 
138
129
  def naked_first
@@ -143,13 +134,12 @@ module ReeDao
143
134
  __original_last
144
135
  end
145
136
 
146
- def delete(entity = nil)
147
- if entity
148
- key_condition = prepare_key_condition_from_entity(entity)
149
- where(key_condition).__original_delete
150
- else
151
- __original_delete
152
- end
137
+ def delete(hash_or_entity = nil)
138
+ return __original_delete if hash_or_entity.nil?
139
+ return where(hash_or_entity).__original_delete if hash_or_entity.is_a?(Hash)
140
+
141
+ key_condition = prepare_key_condition_from_entity(hash_or_entity)
142
+ where(key_condition).__original_delete
153
143
  end
154
144
 
155
145
  def with_lock
@@ -227,4 +227,88 @@ RSpec.describe :build_sqlite_connection do
227
227
  expect(dao.count).to eq(1)
228
228
  }
229
229
  end
230
+
231
+ context "update by condition" do
232
+ it {
233
+ dao.delete_all
234
+
235
+ user = ReeDaoTest::User.new(name: 'John', age: 30)
236
+ other_user = ReeDaoTest::User.new(name: 'Steve', age: 30)
237
+ dao.put(user)
238
+ dao.put(other_user)
239
+
240
+ dao.where(name: 'John').update(name: 'Doe')
241
+
242
+ user = dao.find(user.id)
243
+ other_user = dao.find(other_user.id)
244
+ expect(user.name).to eq('Doe')
245
+ expect(other_user.name).to eq('Steve')
246
+ }
247
+ end
248
+
249
+ context "uodate by entity" do
250
+ it {
251
+ dao.delete_all
252
+
253
+ user = ReeDaoTest::User.new(name: 'John', age: 30)
254
+ dao.put(user)
255
+
256
+ user.name = 'Doe'
257
+
258
+ dao.where(name: 'John').update(user)
259
+
260
+ user = dao.find(user.id)
261
+ expect(user.name).to eq('Doe')
262
+ }
263
+ end
264
+
265
+ context "delete by condition" do
266
+ it {
267
+ dao.delete_all
268
+
269
+ user = ReeDaoTest::User.new(name: 'John', age: 30)
270
+ other_user = ReeDaoTest::User.new(name: 'Steve', age: 30)
271
+
272
+ dao.put(user)
273
+ dao.put(other_user)
274
+
275
+ dao.where(name: 'John').delete(name: 'John')
276
+
277
+ user = dao.find(user.id)
278
+ other_user = dao.find(other_user.id)
279
+
280
+ expect(user).to eq(nil)
281
+ expect(other_user.id).to be_a(Integer)
282
+ }
283
+ end
284
+
285
+ context "delete by entity" do
286
+ it {
287
+ dao.delete_all
288
+
289
+ user = ReeDaoTest::User.new(name: 'John', age: 30)
290
+ dao.put(user)
291
+
292
+ user.name = 'Doe'
293
+
294
+ dao.where(name: 'John').delete(user)
295
+
296
+ user = dao.find(user.id)
297
+ expect(user).to eq(nil)
298
+ }
299
+
300
+ it {
301
+ dao.delete_all
302
+
303
+ user = ReeDaoTest::User.new(name: 'John', age: 30)
304
+ dao.put(user)
305
+
306
+ user.name = 'Doe'
307
+
308
+ dao.delete(user)
309
+
310
+ user = dao.find(user.id)
311
+ expect(user).to eq(nil)
312
+ }
313
+ end
230
314
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.29"
4
+ VERSION = "1.0.30"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ree_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.29
4
+ version: 1.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-30 00:00:00.000000000 Z
11
+ date: 2023-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ree