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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39d0bc2d121a69ebd370d5e3be7387980158b149
4
- data.tar.gz: 0716602a749ed81bd644456388f3f039dddc5c4f
3
+ metadata.gz: fffa361c4decd3f8bfb3706d1c5d5f27c4344c09
4
+ data.tar.gz: db2c74d170e5493354fd390e46d70e9916093e74
5
5
  SHA512:
6
- metadata.gz: 66565417db336737fc0f3c47527f9c8d65d739bd60370d84bca2ab898bc7b7a1b03d33fe4dc7073ae4185aeff7b94dc1f208fee1d8b606cdeef0bb75d7b8faea
7
- data.tar.gz: 64db06826460ad93677ac6d87780a73bec68c6a108b2371aa35aa30ab6bf3d6ee2e06dc561a8d9c660c9c14f4bde3962ca255089c7381ae872c55f32a0567e86
6
+ metadata.gz: 4871d13fed6a47a6aeb5b489a23e23728f28588853afaae0e858d5a2c08b07caaac16cfcfcb93f42cc560e84f247fc145f5b256ad5d02782050d9789156138d9
7
+ data.tar.gz: d67db301a6ffc7826c85f097da73bb8e56aca0fe6623d59313e542cfe2746180093a094a9676c69a7e62becb8de81dc57213da4a2f396033b2dab17d7e2ab43c
data/Appraisals CHANGED
@@ -1,15 +1,15 @@
1
1
  appraise "3.2" do
2
- gem "rails", "~> 3.2.15"
2
+ gem "activerecord", "~> 3.2.0"
3
3
  end
4
4
 
5
5
  appraise "4.0" do
6
- gem "rails", "~> 4.0.0"
6
+ gem "activerecord", "~> 4.0.0"
7
7
  end
8
8
 
9
9
  appraise "4.1" do
10
- gem "rails", "~> 4.1.0"
10
+ gem "activerecord", "~> 4.1.0"
11
11
  end
12
12
 
13
13
  appraise "4.2" do
14
- gem "rails", "~> 4.2.0"
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 3.2.15"
5
+ gem "activerecord", "~> 3.2.0"
6
6
 
7
7
  gemspec :path => "../"
data/gemfiles/4.0.gemfile CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 4.0.0"
5
+ gem "activerecord", "~> 4.0.0"
6
6
 
7
7
  gemspec :path => "../"
data/gemfiles/4.1.gemfile CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 4.1.0"
5
+ gem "activerecord", "~> 4.1.0"
6
6
 
7
7
  gemspec :path => "../"
data/gemfiles/4.2.gemfile CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 4.2.0"
5
+ gem "activerecord", "~> 4.2.0"
6
6
 
7
7
  gemspec :path => "../"
@@ -1,3 +1,3 @@
1
1
  module WhitelistScope
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -15,13 +15,22 @@ module WhitelistScope
15
15
  @whitelist << name
16
16
  end
17
17
 
18
- def call_whitelisted_scope(scope_name = "")
19
- scope_name = scope_name.to_sym unless scope_name == nil
18
+ def call_whitelisted_scope(*scope_names)
19
+ scope_results = nil
20
20
 
21
- if @whitelist.include? scope_name
22
- self.send(scope_name)
23
- else
24
- raise NoMethodError, "The scope you provided, '#{scope_name}', does not exist."
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whitelist_scope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Melody