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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d22429121aad479f8d792514084bd1c8acfe74d
4
- data.tar.gz: 8838cee850318633224c5ab008bfef59ea9eccf2
3
+ metadata.gz: a9532beae77803dc540e0aea17cd94c59f249012
4
+ data.tar.gz: b640afec728316cae2a4e9494770a4cbdbddc68b
5
5
  SHA512:
6
- metadata.gz: 9e9cf6ad40c9615dde262f23ca9ee377fd6f160db9cb2435ecbb900257df7c55f2151b9fd474c83f5c7e28241356687f102f07d0cb430272980a3f8e6f77d648
7
- data.tar.gz: 7ff7ae605d2af28ba557f6a4c97ab8d18c63530b5903b4c38f9d5bdd4773dbf153b6422f7f56bec01df5e8a3f3de0b28b6c59c6ba85ab4a5dcf47565efade4b0
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
- scope.public_send(filter)
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
@@ -1,3 +1,3 @@
1
1
  module Filternator
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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.1
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-08-30 00:00:00.000000000 Z
11
+ date: 2013-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord