lazy_find 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -3
- data/lib/lazy_find/active_record/finder_methods.rb +19 -4
- data/lib/lazy_find/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d6d475dbd5f5dc4a2b798773cbef7d852407feaea1cb88ace69645c3bbead54
|
4
|
+
data.tar.gz: bfd6d82b4ba73e68aa4721213df2d668484b972ea16a0047b7e9e93413f375fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb3689d0e3c19182efd9522adbf70711bcef4c11ff8754b7939fbf628a6b56cd6dc71a6f5673aa0c1ef9f8b1107f0f9b56948fa2ee9231ea5aa7d9db3c478c62
|
7
|
+
data.tar.gz: 8977e3a8d3c8446ef056955f87b286746a1cf6bc88caf625ff2d4366000a06706c4c87fc3539d993a6d3957c2dbf790a3d1985bc59b68cd5370b076375580238
|
data/README.md
CHANGED
@@ -23,20 +23,33 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
26
|
-
|
26
|
+
Simplified the first,last,take methods in ActiveRecord.
|
27
27
|
|
28
28
|
Find the first record (or first N records if a parameter is supplied).
|
29
29
|
|
30
|
-
|
30
|
+
Old Syntax:
|
31
31
|
|
32
32
|
Person.where(:email => "jenorish@gmail").first
|
33
33
|
|
34
|
-
|
34
|
+
New Syntax:
|
35
35
|
|
36
36
|
Person.first(:email => "jenorish@gmail")
|
37
37
|
|
38
38
|
# returns the first three objects fetched by SELECT * FROM people WHERE email= 'jenorish@gmail.com' ORDER BY people.id LIMIT 3
|
39
39
|
|
40
|
+
## Order
|
41
|
+
|
42
|
+
We can find first value with order as well
|
43
|
+
|
44
|
+
Person.first(:email => "jenorish@gmail",:order => "created_at")
|
45
|
+
|
46
|
+
## Select
|
47
|
+
|
48
|
+
Pass select key to select some filds
|
49
|
+
|
50
|
+
Person.first(:email => "jenorish@gmail",:order => "created_at", select: [:name, :email])
|
51
|
+
|
52
|
+
|
40
53
|
|
41
54
|
## Development
|
42
55
|
|
@@ -57,13 +57,28 @@ module LazyFind
|
|
57
57
|
|
58
58
|
def lazy_find(attr,filter)
|
59
59
|
if [Hash, Array, String].include?(attr.class)
|
60
|
-
|
60
|
+
sort_val = extract_order(attr)
|
61
|
+
select_val = extract_select(attr)
|
62
|
+
if select_val
|
63
|
+
where(attr).order(sort_val).select(select_val).send(filter,nil)
|
64
|
+
else
|
65
|
+
where(attr).order(sort_val).send(filter,nil)
|
66
|
+
end
|
61
67
|
else
|
62
|
-
|
68
|
+
send(filter,nil)
|
63
69
|
end
|
64
|
-
|
65
|
-
end
|
70
|
+
end
|
66
71
|
|
72
|
+
def extract_order(attr)
|
73
|
+
return "id" unless attr.class == Hash
|
74
|
+
attr.symbolize_keys!
|
75
|
+
order = attr.delete(:order)
|
76
|
+
order ? order : "id"
|
77
|
+
end
|
78
|
+
def extract_select(attr)
|
79
|
+
return nil unless attr.class == Hash
|
80
|
+
attr.delete(:select)
|
81
|
+
end
|
67
82
|
end
|
68
83
|
end
|
69
84
|
end
|
data/lib/lazy_find/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy_find
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kingston
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|