whitelist_scope 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +5 -5
- data/README.md +3 -0
- data/gemfiles/3.2.gemfile +1 -1
- data/gemfiles/4.0.gemfile +1 -1
- data/gemfiles/4.1.gemfile +1 -1
- data/gemfiles/4.2.gemfile +1 -1
- data/lib/whitelist_scope/version.rb +1 -1
- data/lib/whitelist_scope.rb +15 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fffa361c4decd3f8bfb3706d1c5d5f27c4344c09
|
4
|
+
data.tar.gz: db2c74d170e5493354fd390e46d70e9916093e74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4871d13fed6a47a6aeb5b489a23e23728f28588853afaae0e858d5a2c08b07caaac16cfcfcb93f42cc560e84f247fc145f5b256ad5d02782050d9789156138d9
|
7
|
+
data.tar.gz: d67db301a6ffc7826c85f097da73bb8e56aca0fe6623d59313e542cfe2746180093a094a9676c69a7e62becb8de81dc57213da4a2f396033b2dab17d7e2ab43c
|
data/Appraisals
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
appraise "3.2" do
|
2
|
-
gem "
|
2
|
+
gem "activerecord", "~> 3.2.0"
|
3
3
|
end
|
4
4
|
|
5
5
|
appraise "4.0" do
|
6
|
-
gem "
|
6
|
+
gem "activerecord", "~> 4.0.0"
|
7
7
|
end
|
8
8
|
|
9
9
|
appraise "4.1" do
|
10
|
-
gem "
|
10
|
+
gem "activerecord", "~> 4.1.0"
|
11
11
|
end
|
12
12
|
|
13
13
|
appraise "4.2" do
|
14
|
-
gem "
|
15
|
-
end
|
14
|
+
gem "activerecord", "~> 4.2.0"
|
15
|
+
end
|
data/README.md
CHANGED
@@ -36,6 +36,8 @@ class Item < ActiveRecord::Base
|
|
36
36
|
|
37
37
|
whitelist_scope :most_recent, -> { order(updated_at: :desc) }
|
38
38
|
whitelist_scope :created_first, -> { order(created_at: :asc) }
|
39
|
+
whitelist_scope :approved, -> { where(approved: true) }
|
40
|
+
whitelist_scope :featured, -> { where(featured: true) }
|
39
41
|
end
|
40
42
|
```
|
41
43
|
|
@@ -54,6 +56,7 @@ class ItemController < ApplicationController
|
|
54
56
|
def index
|
55
57
|
@items = Item.call_whitelisted_scope("most_recent") # sorts your items by most recent
|
56
58
|
@others = Item.call_whitelisted_scope(params[:sort]) # sorts by the method specified in the params
|
59
|
+
@approved_features = Item.call_whitelisted_scope("approved", "featured") # call multiple at once
|
57
60
|
end
|
58
61
|
end
|
59
62
|
```
|
data/gemfiles/3.2.gemfile
CHANGED
data/gemfiles/4.0.gemfile
CHANGED
data/gemfiles/4.1.gemfile
CHANGED
data/gemfiles/4.2.gemfile
CHANGED
data/lib/whitelist_scope.rb
CHANGED
@@ -15,13 +15,22 @@ module WhitelistScope
|
|
15
15
|
@whitelist << name
|
16
16
|
end
|
17
17
|
|
18
|
-
def call_whitelisted_scope(
|
19
|
-
|
18
|
+
def call_whitelisted_scope(*scope_names)
|
19
|
+
scope_results = nil
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
scope_names.flatten.each do |scope_name|
|
22
|
+
scope_name = scope_name.to_sym unless scope_name == nil
|
23
|
+
|
24
|
+
if @whitelist.include? scope_name
|
25
|
+
if scope_results
|
26
|
+
scope_results = scope_results.send(scope_name)
|
27
|
+
else
|
28
|
+
scope_results = self.send(scope_name)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
raise NoMethodError, "The scope you provided, '#{scope_name}', does not exist."
|
32
|
+
end
|
25
33
|
end
|
34
|
+
scope_results
|
26
35
|
end
|
27
36
|
end
|