ru.Bee 2.7.6 → 2.7.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da085a4e506cc4a205ced1b110f39c7992e0fa01b92d58efae763d03fc81e881
4
- data.tar.gz: 38c1eb9ccd114bcc29c0c3f16b6759edbaf1306c77fd4595a93dbaa762c58f58
3
+ metadata.gz: b96c111963e69a5ad1fb05d5b1b4e226122015a51a34ceb69ee93f1fe23a2426
4
+ data.tar.gz: f210ad9397a97e65b36fa924dd1c65ea8bc5b88a5bcf7d4643cb4408c6ce0706
5
5
  SHA512:
6
- metadata.gz: 31a67bb08b61d35a35fc84d16d27089a2f0512d3003e96f642ad48718e5433c94c7e6e81af275f3d4134cc5020f97d9882fd8f2f938a806c9787e1c540bfe676
7
- data.tar.gz: baddb5e3958fec54182f1c2a177631231258da5bf6a45c920d8cb87e3c592abe5c029ffa5963901080d2f0d4d47397520c3f8a95ba77cad58a67caeedba27a30
6
+ metadata.gz: b30676699627fcc0f65bf02462ca12138f4226004d5927e6bbb64ad8caa37fc9f6da1ed7c26f40e577392b164bd696d62f89104fa1223347635f0a4fefb11b3c
7
+ data.tar.gz: 8ef41f6739a0c1771c7fab2e484fa1485e38f9a46e1a7fa8509ec40b95630c243008b92d9fa46299aa434480f62da0d6726fc08d9b08b44f4326fe4cc472c660
data/lib/db/test.db CHANGED
Binary file
@@ -208,6 +208,14 @@ module Rubee
208
208
  ::Rubee::AssocArray.new([], self, query_dataset.where(**args))
209
209
  end
210
210
 
211
+ def find_first(args, options = {})
212
+ where(args, options).order(:id).limit(1).last
213
+ end
214
+
215
+ def find_last(args, options = {})
216
+ where(args, options).order(id: :desc).limit(1).last
217
+ end
218
+
211
219
  def order(args, options = {})
212
220
  query_dataset = options[:__query_dataset] || dataset
213
221
 
data/lib/rubee.rb CHANGED
@@ -20,7 +20,7 @@ module Rubee
20
20
  RUBEE_SUPPORT = { "Rubee::Support::Hash" => Hash, "Rubee::Support::String" => String }
21
21
  end
22
22
 
23
- VERSION = '2.7.6'
23
+ VERSION = '2.7.7'
24
24
 
25
25
  require_relative 'rubee/router'
26
26
  require_relative 'rubee/logger'
@@ -119,6 +119,26 @@ describe 'Comment model' do
119
119
  end
120
120
  end
121
121
 
122
+ describe 'find_first' do
123
+ it 'finds first record' do
124
+ Comment.destroy_all
125
+ comment_1 = Comment.create(text: 'test123123')
126
+ comment_2 = Comment.create(text: 'test123123')
127
+ _(Comment.find_first(text: 'test123123').id).must_equal(comment_1.id)
128
+ Comment.destroy_all
129
+ end
130
+ end
131
+
132
+ describe 'find_last' do
133
+ it 'finds last record' do
134
+ Comment.destroy_all
135
+ comment_1 = Comment.create(text: 'test123123')
136
+ comment_2 = Comment.create(text: 'test123123')
137
+ _(Comment.find_last(text: 'test123123').id).must_equal(comment_2.id)
138
+ Comment.destroy_all
139
+ end
140
+ end
141
+
122
142
  describe 'method' do
123
143
  it 'updates existing model' do
124
144
  comment = Comment.new(text: 'test 1')
data/readme.md CHANGED
@@ -380,7 +380,16 @@ Get all records scoped by a field
380
380
  irb(main):005> User.where(email: "ok23@ok.com")
381
381
  => [#<User:0x000000010cfaa5c0 @email="ok23@ok.com", @id=2, @password="123">]
382
382
  ```
383
-
383
+ Get the first record. It is a shortcut for `User.where(email: "ok23@ok.com").order(:id).limit(1).last`
384
+ ```ruby
385
+ irb(main):006> User.find_first(email: "ok23@ok.com")
386
+ => #<User:0x000000010cfaa5c0 @email="ok23@ok.com", @id=2, @password="123">
387
+ ```
388
+ Get the last record. It is a shortcut for `User.where(email: "ok23@ok.com").order(id: :desc).limit(1).last`
389
+ ```ruby
390
+ irb(main):007> User.find_last(email: "ok23@ok.com")
391
+ => #<User:0x000000010cfaa5c0 @email="ok23@ok.com", @id=2, @password="123">
392
+ ```
384
393
  Get all records
385
394
  ```ruby
386
395
  irb(main):001> User.all
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ru.Bee
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.6
4
+ version: 2.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Saltykov