lazy_find 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -1
- data/lib/lazy_find/active_record/finder_methods.rb +5 -5
- data/lib/lazy_find/version.rb +1 -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: c35f1177bc46404a6604d910ef5edae2bafad141bd28ae816a8af30c0dbef423
|
4
|
+
data.tar.gz: ef8d2c6a7daa61c0c0a4cfe56d09a4565f2424b03facdac459d3b5083ae7d312
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57f1c0e22f9070ce762ddf1a57e66b7333fde4dad699d7d5c71025c3af8ca86649dc9fb96343e819841dcadbfeaa39b913f1dc45cb396ccdbb04c5f2278f9eb8
|
7
|
+
data.tar.gz: e65219591c790896c6bc36507678ec7168fe02dc963ac5e27375065047dc29d2e0ea11f2e10cf0e1853d779de21095ea34aa158d88d5b398f8b3320d50e5442d
|
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# LazyFind
|
2
2
|
|
3
|
+
## Description
|
4
|
+
|
5
|
+
Simplified the first,last,take methods in ActiveRecord.So instead of using where and first, you can directly use first.
|
6
|
+
|
7
|
+
|
3
8
|
## Installation
|
4
9
|
|
5
10
|
Add this line to your application's Gemfile:
|
@@ -18,7 +23,20 @@ Or install it yourself as:
|
|
18
23
|
|
19
24
|
## Usage
|
20
25
|
|
21
|
-
|
26
|
+
Simplified the first,last,take methods in ActiveRecord.
|
27
|
+
|
28
|
+
Find the first record (or first N records if a parameter is supplied).
|
29
|
+
|
30
|
+
Old Syntax:
|
31
|
+
|
32
|
+
Person.where(:email => "jenorish@gmail").first
|
33
|
+
|
34
|
+
New Syntax:
|
35
|
+
|
36
|
+
Person.first(:email => "jenorish@gmail")
|
37
|
+
|
38
|
+
# returns the first three objects fetched by SELECT * FROM people WHERE email= 'jenorish@gmail.com' ORDER BY people.id LIMIT 3
|
39
|
+
|
22
40
|
|
23
41
|
## Development
|
24
42
|
|
@@ -2,7 +2,7 @@ module LazyFind
|
|
2
2
|
module ActiveRecord
|
3
3
|
module FinderMethods
|
4
4
|
|
5
|
-
|
5
|
+
MAPPING = {:first => 0, :last => -1}
|
6
6
|
# Find the first record (or first N records if a parameter is supplied).
|
7
7
|
# If no order is defined it will order by primary key.
|
8
8
|
#
|
@@ -56,12 +56,12 @@ module LazyFind
|
|
56
56
|
private
|
57
57
|
|
58
58
|
def lazy_find(attr,filter)
|
59
|
-
|
60
|
-
|
61
|
-
where(attr).send(filter,nil)
|
59
|
+
if [Hash, Array, String].include?(attr.class)
|
60
|
+
result = where(attr).send(filter,nil)
|
62
61
|
else
|
63
|
-
|
62
|
+
result = send(filter,nil)
|
64
63
|
end
|
64
|
+
result
|
65
65
|
end
|
66
66
|
|
67
67
|
end
|
data/lib/lazy_find/version.rb
CHANGED