lazy_find 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/lazy_find/active_record/finder_methods.rb +13 -2
- 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: 976ebc2609a7de85534e74f8d7cee02e7023819d7cc09f4effff81af82bf2d51
|
4
|
+
data.tar.gz: ba0944f4f578ee8c3bafe7dc3a8be95f9000f3868dd61ea083fbe376420080d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17d9e4b330a7881ca7771a104ad0b28cf15e0a00d7f17ed13190f22140aa04c2c411ec8ab6a7585467cbf8079601bc83fc0cd675226c496d6dc52abd08cd6d1b
|
7
|
+
data.tar.gz: b2894589577409993c57ac4a9d5e20a81bc29f4adcc7722f9accbb511cc39efabf71b7b4080f727fa64f4c98dc84fe4591ce2199001d4a7d1df1d21d8c0d98cd
|
data/README.md
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
Simplified the first,last,take methods in ActiveRecord.So instead of using where and first, you can directly use first.
|
6
6
|
|
7
7
|
|
8
|
+
|
8
9
|
## Installation
|
9
10
|
|
10
11
|
Add this line to your application's Gemfile:
|
@@ -49,6 +50,15 @@ Or install it yourself as:
|
|
49
50
|
|
50
51
|
Person.first(:email => "jenorish@gmail",:order => "created_at", select: [:name, :email])
|
51
52
|
|
53
|
+
## New methods
|
54
|
+
|
55
|
+
We can use find all in lazy way by passing like below
|
56
|
+
|
57
|
+
Person.lazy_all(:email => "jenorish@gmail",:order => "created_at")
|
58
|
+
|
59
|
+
And support `Rails 3` where syntax
|
60
|
+
|
61
|
+
Person.lazy_where(:email => "jenorish@gmail",:order => "created_at")
|
52
62
|
|
53
63
|
|
54
64
|
## Development
|
@@ -53,6 +53,17 @@ module LazyFind
|
|
53
53
|
lazy_find(attr,:take)
|
54
54
|
end
|
55
55
|
|
56
|
+
# posts = Post.all
|
57
|
+
# posts.size # Fires "select count(*) from posts" and returns the count
|
58
|
+
# posts.each {|p| puts p.name } # Fires "select * from posts" and loads post objects
|
59
|
+
|
60
|
+
def lazy_all(attr = nil)
|
61
|
+
return all if attr.blank?
|
62
|
+
lazy_find(attr,:all)
|
63
|
+
end
|
64
|
+
|
65
|
+
alias_method :lazy_where, :lazy_all
|
66
|
+
|
56
67
|
private
|
57
68
|
|
58
69
|
def lazy_find(attr,filter)
|
@@ -60,9 +71,9 @@ module LazyFind
|
|
60
71
|
sort_val = extract_order(attr)
|
61
72
|
select_val = extract_select(attr)
|
62
73
|
if select_val
|
63
|
-
where(attr).order(sort_val).select(select_val).send(filter
|
74
|
+
where(attr).order(sort_val).select(select_val).send(filter)
|
64
75
|
else
|
65
|
-
where(attr).order(sort_val).send(filter
|
76
|
+
where(attr).order(sort_val).send(filter)
|
66
77
|
end
|
67
78
|
else
|
68
79
|
send(filter,nil)
|
data/lib/lazy_find/version.rb
CHANGED