filternator 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/filternator/apply_filter.rb +6 -1
- data/lib/filternator/version.rb +1 -1
- data/spec/integration_spec.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9532beae77803dc540e0aea17cd94c59f249012
|
4
|
+
data.tar.gz: b640afec728316cae2a4e9494770a4cbdbddc68b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef551844012da8879baacad9ba6afa518acbca0860e813cad34edca68b6a7492efd02ed32098d330d14a411c4e6d7101c292ecbf88b58bfa85bb89de37d3f307
|
7
|
+
data.tar.gz: 47e44181a00ef9e7b89a8f51aa6fcc14556beb3d4f06edfa843fa1bcee3d17f9a5c43e257d9e1659eceec9f446f96bf7061119db5e4d2ed652afc82c517097c7
|
@@ -46,7 +46,12 @@ module Filternator
|
|
46
46
|
|
47
47
|
def filtered_scope
|
48
48
|
if valid_filter?
|
49
|
-
|
49
|
+
# ignore 'all' on relations
|
50
|
+
if scope.is_a?(::ActiveRecord::Relation) && filter.to_s == "all"
|
51
|
+
scope
|
52
|
+
else
|
53
|
+
scope.public_send(filter)
|
54
|
+
end
|
50
55
|
else
|
51
56
|
scope
|
52
57
|
end
|
data/lib/filternator/version.rb
CHANGED
data/spec/integration_spec.rb
CHANGED
@@ -13,6 +13,9 @@ class Widget < ActiveRecord::Base
|
|
13
13
|
%w(all busy)
|
14
14
|
end
|
15
15
|
scope :busy, -> { where state: "busy" }
|
16
|
+
def self.ordered
|
17
|
+
order("state DESC")
|
18
|
+
end
|
16
19
|
end
|
17
20
|
|
18
21
|
describe Filternator do
|
@@ -24,7 +27,7 @@ describe Filternator do
|
|
24
27
|
example "a basic filter" do
|
25
28
|
Widget.create! id: 1, state: "idle"
|
26
29
|
Widget.create! id: 2, state: "busy"
|
27
|
-
filter = Filternator.new(scope: Widget)
|
30
|
+
filter = Filternator.new(scope: Widget.ordered)
|
28
31
|
result = filter.apply(filter: "busy")
|
29
32
|
expect(result.as_json).to eq(
|
30
33
|
{
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filternator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|