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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c35f1177bc46404a6604d910ef5edae2bafad141bd28ae816a8af30c0dbef423
4
- data.tar.gz: ef8d2c6a7daa61c0c0a4cfe56d09a4565f2424b03facdac459d3b5083ae7d312
3
+ metadata.gz: 6d6d475dbd5f5dc4a2b798773cbef7d852407feaea1cb88ace69645c3bbead54
4
+ data.tar.gz: bfd6d82b4ba73e68aa4721213df2d668484b972ea16a0047b7e9e93413f375fc
5
5
  SHA512:
6
- metadata.gz: 57f1c0e22f9070ce762ddf1a57e66b7333fde4dad699d7d5c71025c3af8ca86649dc9fb96343e819841dcadbfeaa39b913f1dc45cb396ccdbb04c5f2278f9eb8
7
- data.tar.gz: e65219591c790896c6bc36507678ec7168fe02dc963ac5e27375065047dc29d2e0ea11f2e10cf0e1853d779de21095ea34aa158d88d5b398f8b3320d50e5442d
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
- Simplified the first,last,take methods in ActiveRecord.
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
- Old Syntax:
30
+ Old Syntax:
31
31
 
32
32
  Person.where(:email => "jenorish@gmail").first
33
33
 
34
- New Syntax:
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
- result = where(attr).send(filter,nil)
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
- result = send(filter,nil)
68
+ send(filter,nil)
63
69
  end
64
- result
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
@@ -1,3 +1,3 @@
1
1
  module LazyFind
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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-15 00:00:00.000000000 Z
11
+ date: 2018-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler