whitelist_scope 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 39d0bc2d121a69ebd370d5e3be7387980158b149
4
+ data.tar.gz: 0716602a749ed81bd644456388f3f039dddc5c4f
5
+ SHA512:
6
+ metadata.gz: 66565417db336737fc0f3c47527f9c8d65d739bd60370d84bca2ab898bc7b7a1b03d33fe4dc7073ae4185aeff7b94dc1f208fee1d8b606cdeef0bb75d7b8faea
7
+ data.tar.gz: 64db06826460ad93677ac6d87780a73bec68c6a108b2371aa35aa30ab6bf3d6ee2e06dc561a8d9c660c9c14f4bde3962ca255089c7381ae872c55f32a0567e86
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/db/*.sqlite3-journal
6
+ spec/dummy/log/*.log
7
+ spec/dummy/tmp/
8
+ spec/dummy/.sass-cache
9
+ bin/
10
+ .DS_Store
11
+ gemfiles/*.lock
12
+ coverage/
13
+ coverage/**/*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format Fuubar
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ script: bundle exec rspec
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
7
+ - 2.2.0
8
+ gemfile:
9
+ - gemfiles/3.2.gemfile
10
+ - gemfiles/4.0.gemfile
11
+ - gemfiles/4.1.gemfile
12
+ - gemfiles/4.2.gemfile
13
+ branches:
14
+ only:
15
+ - stable
16
+ - develop
data/Appraisals ADDED
@@ -0,0 +1,15 @@
1
+ appraise "3.2" do
2
+ gem "rails", "~> 3.2.15"
3
+ end
4
+
5
+ appraise "4.0" do
6
+ gem "rails", "~> 4.0.0"
7
+ end
8
+
9
+ appraise "4.1" do
10
+ gem "rails", "~> 4.1.0"
11
+ end
12
+
13
+ appraise "4.2" do
14
+ gem "rails", "~> 4.2.0"
15
+ end
@@ -0,0 +1,35 @@
1
+ #Code of Conduct
2
+
3
+ Summary
4
+ -------
5
+
6
+ Harassment in code and discussion or violation of physical boundaries is completely unacceptable anywhere in WhitelistScope’s project codebases, issue trackers, chatrooms, mailing lists, meetups, etc. Violations will result in being warned, blocked or banned by the core team at or before the 3rd violation.
7
+
8
+ In detail
9
+ ---------
10
+
11
+ Harassment includes offensive verbal comments related to gender identity, gender expression, sexual orientation, disability, physical appearance, body size, race, ethnicity, nationality, religion, as well as sexual images, deliberate intimidation, stalking, sustained disruption, and unwelcome sexual attention.
12
+
13
+ Individuals asked to stop any harassing behavior are expected to comply immediately.
14
+
15
+ Maintainers, including members of the core team, are also subject to the anti-harassment policy.
16
+
17
+ If anyone engages in harassing behavior, including maintainers, we may take appropriate action, up to and including warning the offender, deletion of comments, removal from the project’s codebase and communication systems, and escalation to GitHub support.
18
+
19
+ If you are being harassed, notice that someone else is being harassed, or have any other concerns, please contact a member of the core team immediately.
20
+
21
+ We expect everyone to follow these rules in any and all public spaces associated with the WhitelistScope project, including codebases, issue trackers, chatrooms, social media, and mailing lists. Additonally, we expect members of the core team to follow these rules on personal accounts where they are associated with the project, for instance in tweets or forums posts from an account where they identify themselves as a project maintainer.
22
+
23
+ Finally, don't forget that it is human to make mistakes! We all do. Let’s work together to help each other, resolve issues, and learn from the mistakes that we will all inevitably make from time to time.
24
+
25
+ Thanks
26
+ ------
27
+
28
+ Thanks to the [Thoughtbot Code of Conduct](https://thoughtbot.com/open-source-code-of-conduct), [CocoaPods Code of Conduct](https://github.com/CocoaPods/CocoaPods/blob/master/CODE_OF_CONDUCT.md), [Bundler Code of Conduct](http://bundler.io/conduct.html), [JSConf Code of Conduct](http://jsconf.com/codeofconduct.html), and [Contributor Covenant](http://contributor-covenant.org/) for inspiration and ideas.
29
+
30
+ License
31
+ -------
32
+
33
+ To the extent possible under law, WhitelistScope has waived all copyright and related or neighboring rights to the WhitelistScope Code of Conduct. This work is published from the United States.
34
+
35
+ [![CC0](https://i.creativecommons.org/p/zero/1.0/88x31.png)](https://creativecommons.org/publicdomain/zero/1.0/)
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Declare your gem's dependencies in whitelist_scope.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use a debugger
14
+ # gem 'byebug', group: [:development, :test]
data/Gemfile.lock ADDED
@@ -0,0 +1,97 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ whitelist_scope (0.1.0)
5
+ activerecord (>= 3.2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (4.2.4)
11
+ activesupport (= 4.2.4)
12
+ builder (~> 3.1)
13
+ activerecord (4.2.4)
14
+ activemodel (= 4.2.4)
15
+ activesupport (= 4.2.4)
16
+ arel (~> 6.0)
17
+ activesupport (4.2.4)
18
+ i18n (~> 0.7)
19
+ json (~> 1.7, >= 1.7.7)
20
+ minitest (~> 5.1)
21
+ thread_safe (~> 0.3, >= 0.3.4)
22
+ tzinfo (~> 1.1)
23
+ appraisal (2.1.0)
24
+ bundler
25
+ rake
26
+ thor (>= 0.14.0)
27
+ arel (6.0.3)
28
+ builder (3.2.2)
29
+ coveralls (0.8.2)
30
+ json (~> 1.8)
31
+ rest-client (>= 1.6.8, < 2)
32
+ simplecov (~> 0.10.0)
33
+ term-ansicolor (~> 1.3)
34
+ thor (~> 0.19.1)
35
+ diff-lcs (1.2.5)
36
+ docile (1.1.5)
37
+ domain_name (0.5.24)
38
+ unf (>= 0.0.5, < 1.0.0)
39
+ fuubar (2.0.0)
40
+ rspec (~> 3.0)
41
+ ruby-progressbar (~> 1.4)
42
+ http-cookie (1.0.2)
43
+ domain_name (~> 0.5)
44
+ i18n (0.7.0)
45
+ json (1.8.3)
46
+ mime-types (2.6.2)
47
+ minitest (5.8.1)
48
+ netrc (0.10.3)
49
+ rake (10.4.2)
50
+ rest-client (1.8.0)
51
+ http-cookie (>= 1.0.2, < 2.0)
52
+ mime-types (>= 1.16, < 3.0)
53
+ netrc (~> 0.7)
54
+ rspec (3.3.0)
55
+ rspec-core (~> 3.3.0)
56
+ rspec-expectations (~> 3.3.0)
57
+ rspec-mocks (~> 3.3.0)
58
+ rspec-core (3.3.2)
59
+ rspec-support (~> 3.3.0)
60
+ rspec-expectations (3.3.1)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.3.0)
63
+ rspec-mocks (3.3.2)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.3.0)
66
+ rspec-support (3.3.0)
67
+ ruby-progressbar (1.7.5)
68
+ simplecov (0.10.0)
69
+ docile (~> 1.1.0)
70
+ json (~> 1.8)
71
+ simplecov-html (~> 0.10.0)
72
+ simplecov-html (0.10.0)
73
+ sqlite3 (1.3.10)
74
+ term-ansicolor (1.3.2)
75
+ tins (~> 1.0)
76
+ thor (0.19.1)
77
+ thread_safe (0.3.5)
78
+ tins (1.6.0)
79
+ tzinfo (1.2.2)
80
+ thread_safe (~> 0.1)
81
+ unf (0.1.4)
82
+ unf_ext
83
+ unf_ext (0.0.7.1)
84
+
85
+ PLATFORMS
86
+ ruby
87
+
88
+ DEPENDENCIES
89
+ appraisal
90
+ coveralls
91
+ fuubar
92
+ rspec
93
+ sqlite3
94
+ whitelist_scope!
95
+
96
+ BUNDLED WITH
97
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Melody
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ #Whitelist Scope
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/whitelist_scope.svg)](http://badge.fury.io/rb/whitelist_scope)[![Build Status](https://travis-ci.org/meltheadorable/whitelist_scope.svg)](https://travis-ci.org/meltheadorable/whitelist_scope)[![Code Climate](https://codeclimate.com/github/meltheadorable/whitelist_scope/badges/gpa.svg)](https://codeclimate.com/github/meltheadorable/whitelist_scope)[![Coverage Status](https://coveralls.io/repos/meltheadorable/whitelist_scope/badge.svg?branch=stable)](https://coveralls.io/r/meltheadorable/whitelist_scope?branch=stable)[![Dependency Status](https://gemnasium.com/meltheadorable/whitelist_scope.svg)](https://gemnasium.com/meltheadorable/whitelist_scope)[![Documentation Status](http://inch-ci.org/github/meltheadorable/whitelist_scope.svg?branch=develop)](http://inch-ci.org/github/meltheadorable/whitelist_scope)
4
+
5
+ `whitelist_scope` provides a safe way to register and call scopes inside rails apps
6
+
7
+ > #### :warning: **Warning**:
8
+ >
9
+ > whitelist_scope is in the very early stages of development right now, has few tests and could introduce breaking changes. Use at your own risk.
10
+
11
+ Getting Started
12
+ ---------------
13
+
14
+ To get started, add whitelist_scope to your gemfile:
15
+
16
+ `gem 'whitelist_scope'`
17
+
18
+ Then run `bundle install` to fetch the current version.
19
+
20
+ Usage
21
+ -----
22
+
23
+ Using WhitelistScope is very simple. All you need to do is specify whitelisted scopes in your models, then call `call_whitelisted_scope` in your controllers naming a scope.
24
+
25
+ ### Models
26
+
27
+ Whitelist Scope acts as a wrapper around ActiveRecord scopes, providing a tiny bit of extra functionality to keep track of the whitelist.
28
+
29
+ If you don't know what scopes are, [you can read about them here](http://guides.rubyonrails.org/active_record_querying.html#scopes):
30
+
31
+ First you'll need to extend WhitelistScope, and then you can specify your scopes.
32
+
33
+ ```ruby
34
+ class Item < ActiveRecord::Base
35
+ extend WhitelistScope # includes the whitelist_scope methods in your model
36
+
37
+ whitelist_scope :most_recent, -> { order(updated_at: :desc) }
38
+ whitelist_scope :created_first, -> { order(created_at: :asc) }
39
+ end
40
+ ```
41
+
42
+ `whitelist_scope` takes a symbol as a name, and a lambda, exactly like an ActiveRecord scope.
43
+
44
+ ### Controllers
45
+
46
+ For your controllers, WhitelistScope provides the `call_whitelisted_scope` method, which takes a string naming one of your whitelisted scopes as an argument. Because WhitelistScope uses scopes under the hood, it can be chained with other scopes.
47
+
48
+ > #### :warning: **Warning**:
49
+ >
50
+ > The `whitelist_scope` method will raise a `NoMethodError` if it cannot find a whitelisted with the name you passed in.
51
+
52
+ ```ruby
53
+ class ItemController < ApplicationController
54
+ def index
55
+ @items = Item.call_whitelisted_scope("most_recent") # sorts your items by most recent
56
+ @others = Item.call_whitelisted_scope(params[:sort]) # sorts by the method specified in the params
57
+ end
58
+ end
59
+ ```
60
+
61
+ Because it uses scopes under the hood, WhitelistScope also provides separate methods for your whitelisted scopes:
62
+
63
+ ```ruby
64
+ class ItemController < ApplicationController
65
+ def index
66
+ @items = Item.created_first # all of your Items, sorted by creation date
67
+ end
68
+ end
69
+ ```
70
+
71
+ License
72
+ -------
73
+
74
+ WhitelistScope is released under the [MIT License](LICENSE)
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Whitelist Scope'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 3.2.15"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.0.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.1.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.2.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,3 @@
1
+ module WhitelistScope
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ require "whitelist_scope/version"
2
+
3
+ module WhitelistScope
4
+ attr_reader :whitelist
5
+
6
+ def whitelist_scope(name, body)
7
+ @whitelist ||= []
8
+ name = name.to_sym
9
+
10
+ if self.respond_to?(name)
11
+ raise ArgumentError, "Could not create scope, There is an existing method with this name."
12
+ end
13
+
14
+ scope name, body
15
+ @whitelist << name
16
+ end
17
+
18
+ def call_whitelisted_scope(scope_name = "")
19
+ scope_name = scope_name.to_sym unless scope_name == nil
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."
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'whitelist_scope/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "whitelist_scope"
8
+ spec.version = WhitelistScope::VERSION
9
+ spec.authors = ["Melody"]
10
+ spec.email = ["meltheadorable@gmail.com"]
11
+
12
+ spec.homepage = "https://github.com/meltheadorable/sortify"
13
+ spec.summary = "whitelist_scope provides a safe way to register and call scopes inside rails apps"
14
+ spec.description = "whitelist_scope acts as a wrapper around ActiveRecord scopes, providing a tiny bit of extra functionality to keep track of whitelisted scopes and call them from user input."
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "activerecord", ">= 3.2.0"
23
+
24
+ spec.add_development_dependency "sqlite3"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "fuubar"
27
+ spec.add_development_dependency "coveralls"
28
+ spec.add_development_dependency "appraisal"
29
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: whitelist_scope
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Melody
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fuubar
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: appraisal
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: whitelist_scope acts as a wrapper around ActiveRecord scopes, providing
98
+ a tiny bit of extra functionality to keep track of whitelisted scopes and call them
99
+ from user input.
100
+ email:
101
+ - meltheadorable@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Appraisals
110
+ - CODE_OF_CONDUCT.md
111
+ - Gemfile
112
+ - Gemfile.lock
113
+ - LICENSE
114
+ - README.md
115
+ - Rakefile
116
+ - gemfiles/3.2.gemfile
117
+ - gemfiles/4.0.gemfile
118
+ - gemfiles/4.1.gemfile
119
+ - gemfiles/4.2.gemfile
120
+ - lib/whitelist_scope.rb
121
+ - lib/whitelist_scope/version.rb
122
+ - whitelist_scope.gemspec
123
+ homepage: https://github.com/meltheadorable/sortify
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.4.5
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: whitelist_scope provides a safe way to register and call scopes inside rails
147
+ apps
148
+ test_files: []
149
+ has_rdoc: