sinatra-pundit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 24a0560fedd81f8b9a1d74d24b2aedaac12a95b4
4
+ data.tar.gz: 8ede619c30c3343163fa9df70379eb3737e58651
5
+ SHA512:
6
+ metadata.gz: 497edee53718da5a5cbac17aac8497490025ec705e3d5297cd6a07d56f24270866f6be2fe4eae1a8a42b09ecb43b5d52ada1810a28e19e610e3ed0a0b3a91e12
7
+ data.tar.gz: d717c0cc3701628b842c7d6fbd97c66014a4cb7ffc0b445c981e77a021e37bd27d8151bca91493155d6647eb3aea293663c07c58f12e0ce03245489c22f62df4
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Sergio Martin
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Sinatra::Pundit
2
+
3
+ A lightweight wrapper for the [Pundit](https://github.com/elabs/pundit) authorization gem. Provides authorization Pundit's helpers to use in Sinatra applications.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'sinatra-pundit'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install sinatra-pundit
20
+
21
+ ## Usage
22
+
23
+ Require the extension in your application:
24
+
25
+ ```ruby
26
+ require 'sinatra/pundit'
27
+ ```
28
+
29
+ If your application is “classic”, you’re done. The `authorize` method should be available to your application.
30
+
31
+ If your application subclasses Sinatra::Base, you have to register the extension in your subclass:
32
+
33
+ ```ruby
34
+ register Sinatra::Pundit
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/smartinm/sinatra-pundit.
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
44
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/example/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :sinatra do
4
+ gem 'sinatra'
5
+ gem 'sinatra-contrib'
6
+ gem 'sinatra-pundit', path: '../..'
7
+ end
8
+
9
+ group :development do
10
+ gem 'foreman'
11
+ end
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ sinatra-pundit (0.1.0)
5
+ pundit (~> 1.1.0)
6
+ sinatra (~> 1.4.7)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (4.2.6)
12
+ i18n (~> 0.7)
13
+ json (~> 1.7, >= 1.7.7)
14
+ minitest (~> 5.1)
15
+ thread_safe (~> 0.3, >= 0.3.4)
16
+ tzinfo (~> 1.1)
17
+ backports (3.6.8)
18
+ foreman (0.80.2)
19
+ thor (~> 0.19.1)
20
+ i18n (0.7.0)
21
+ json (1.8.3)
22
+ minitest (5.8.4)
23
+ multi_json (1.11.3)
24
+ pundit (1.1.0)
25
+ activesupport (>= 3.0.0)
26
+ rack (1.6.4)
27
+ rack-protection (1.5.3)
28
+ rack
29
+ rack-test (0.6.3)
30
+ rack (>= 1.0)
31
+ sinatra (1.4.7)
32
+ rack (~> 1.5)
33
+ rack-protection (~> 1.4)
34
+ tilt (>= 1.3, < 3)
35
+ sinatra-contrib (1.4.7)
36
+ backports (>= 2.0)
37
+ multi_json
38
+ rack-protection
39
+ rack-test
40
+ sinatra (~> 1.4.0)
41
+ tilt (>= 1.3, < 3)
42
+ thor (0.19.1)
43
+ thread_safe (0.3.5)
44
+ tilt (2.0.2)
45
+ tzinfo (1.2.2)
46
+ thread_safe (~> 0.1)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ foreman
53
+ sinatra
54
+ sinatra-contrib
55
+ sinatra-pundit!
56
+
57
+ BUNDLED WITH
58
+ 1.11.2
data/example/Procfile ADDED
@@ -0,0 +1 @@
1
+ web: bundle exec ruby app.rb -p $PORT
data/example/app.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'sinatra'
2
+ require 'sinatra/pundit'
3
+
4
+ use Rack::Auth::Basic, "Restricted Area" do |username, password|
5
+ %w(admin member).include?(username)
6
+ end
7
+
8
+ configure do
9
+ set :show_exceptions, :after_handler
10
+ error Pundit::NotAuthorizedError do
11
+ status 403
12
+ body "Forbidden"
13
+ end
14
+ end
15
+
16
+ current_user do
17
+ request.env['REMOTE_USER']
18
+ end
19
+
20
+ get '/' do
21
+ "Hello World!"
22
+ end
23
+
24
+ get '/admin' do
25
+ authorize :example, :access?
26
+ "Restricted Admin Area"
27
+ end
@@ -0,0 +1,9 @@
1
+ class ApplicationPolicy
2
+ attr_reader :user, :record
3
+
4
+ def initialize(user, record)
5
+ raise Pundit::NotAuthorizedError, "must be logged in" unless user
6
+ @user = user
7
+ @record = record
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ class ExamplePolicy < ApplicationPolicy
2
+ def access?
3
+ user == 'admin'
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+ require "pundit"
2
+ require "sinatra/base"
3
+ require "sinatra/pundit/version"
4
+
5
+ module Sinatra
6
+ module Pundit
7
+ module Helpers
8
+ include ::Pundit
9
+
10
+ protected
11
+
12
+ def authorize(record, query)
13
+ # query must be a required parameter because if is omitted
14
+ # Pundit tries to uses the Rails controller action name.
15
+ super
16
+ end
17
+
18
+ def pundit_user
19
+ instance_eval(&settings.pundit_user_block) if settings.respond_to?(:pundit_user_block)
20
+ end
21
+ end
22
+
23
+ def current_user(&block)
24
+ set :pundit_user_block, Proc.new { block }
25
+ end
26
+
27
+ def self.registered(app)
28
+ $LOAD_PATH << File.join(app.settings.root, 'policies')
29
+ Dir[File.join(app.settings.root, 'policies', '/**/*.rb')].each { |file| require file }
30
+
31
+ app.helpers Pundit::Helpers
32
+ end
33
+ end
34
+
35
+ register Pundit
36
+ end
@@ -0,0 +1,5 @@
1
+ module Sinatra
2
+ module Pundit
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sinatra/pundit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sinatra-pundit"
8
+ spec.version = Sinatra::Pundit::VERSION
9
+ spec.authors = ["Sergio Martín Morillas"]
10
+ spec.email = ["smartin@flexiant.com"]
11
+
12
+ spec.summary = %q{Pundit authorization wrapper for Sinatra.}
13
+ spec.description = %q{Minimal authorization through OO design and pure Ruby classes in your Sinatra application.}
14
+ spec.homepage = "https://github.com/smartinm/sinatra-pundit"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "pundit", "~> 1.0"
21
+ spec.add_dependency "sinatra", "~> 1.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-pundit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergio Martín Morillas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pundit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Minimal authorization through OO design and pure Ruby classes in your
84
+ Sinatra application.
85
+ email:
86
+ - smartin@flexiant.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - example/Gemfile
99
+ - example/Gemfile.lock
100
+ - example/Procfile
101
+ - example/app.rb
102
+ - example/policies/application_policy.rb
103
+ - example/policies/example_policy.rb
104
+ - lib/sinatra/pundit.rb
105
+ - lib/sinatra/pundit/version.rb
106
+ - sinatra-pundit.gemspec
107
+ homepage: https://github.com/smartinm/sinatra-pundit
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.6
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Pundit authorization wrapper for Sinatra.
131
+ test_files: []
132
+ has_rdoc: