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 +4 -4
- data/lib/db/test.db +0 -0
- data/lib/rubee/models/sequel_object.rb +8 -0
- data/lib/rubee.rb +1 -1
- data/lib/tests/models/comment_model_test.rb +20 -0
- data/readme.md +10 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b96c111963e69a5ad1fb05d5b1b4e226122015a51a34ceb69ee93f1fe23a2426
|
|
4
|
+
data.tar.gz: f210ad9397a97e65b36fa924dd1c65ea8bc5b88a5bcf7d4643cb4408c6ce0706
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
@@ -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
|