grape-cancan 0.0.1

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: 38721406628690b22a71b1089852cf9817243d66
4
+ data.tar.gz: 909778e00ac3260ab4b8e2756f47ca9073d54532
5
+ SHA512:
6
+ metadata.gz: a6facc9a56bc9889ed35589dcd11b3f3ff73296eeab18ad5d9a2416bcaf6e8c75c214daf52a0fd5dde1d8ba9fec9be673ec7ba65f695269f8a459f7475e43b47
7
+ data.tar.gz: 35d2caf20054ad54f7a7618f0015792df7d88ba57231e7b4fc395915658f22dfc365bbed4c01110d181a2cb663ff74bcf2597be36e213524dd2445bd5ffab549
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grape-cancan.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ray Zane
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # Grape::CanCan
2
+
3
+ Use CanCan to authorize your Grape endpoints.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'grape-cancan'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install grape-cancan
20
+
21
+ __NOTE:__ The [cancan](https://github.com/ryanb/cancan) gem by Ryan Bates is no longer maintained. If you're still using that gem, you should consider replacing it with [cancancan](https://github.com/CanCanCommunity/cancancan).
22
+
23
+ ## Usage
24
+
25
+ This gem adds the __can?__, __cannot?__, and __authorize!__ helper methods to all Grape API endpoints. This gem expects you to have a __current_user__ helper.
26
+
27
+ ```ruby
28
+ class Users < Grape::API
29
+ resource :users
30
+
31
+ get '/:id' do
32
+ @user = User.find(params[:id])
33
+ authorize! :read, @user
34
+ @user
35
+ end
36
+ end
37
+ ```
38
+
39
+ #### Authorizing All Routes
40
+
41
+ The __authorize_routes!__ method allows you to automatically perform authorization on all routes. Just add the `:authorize` key to the route options and call `authorize_routes!`.
42
+
43
+ Authorization will be skipped on actions that don't provide the `:authorize` route option.
44
+
45
+ ```ruby
46
+ class Users < Grape::API
47
+ resource :users
48
+ authorize_routes!
49
+
50
+ get '/', authorize: [:read, User] do
51
+ User.all
52
+ end
53
+ end
54
+ ```
55
+
56
+ #### Authorizing Specific Routes
57
+
58
+ For more fine grained control, you can call __authorize_route!__ in a `before` block.
59
+
60
+ ```ruby
61
+ class Users < Grape::API
62
+ resource :users
63
+
64
+ before do
65
+ authorize_route! if user_signed_in?
66
+ end
67
+
68
+ get '/', authorize: [:read, User] do
69
+ User.all
70
+ end
71
+ end
72
+ ```
73
+
74
+ ## Contributing
75
+
76
+ 1. Fork it ( https://github.com/rzane/grape-cancan/fork )
77
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
78
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
79
+ 4. Push to the branch (`git push origin my-new-feature`)
80
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -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 'grape/cancan/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "grape-cancan"
8
+ spec.version = Grape::CanCan::VERSION
9
+ spec.authors = ["Ray Zane"]
10
+ spec.email = ["raymondzane@gmail.com"]
11
+ spec.summary = %q{Authorize your Grape API with CanCan}
12
+ spec.description = %q{Authorize your Grape API with CanCan}
13
+ spec.homepage = "https://github.com/rzane/grape-cancan"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'grape', '>= 0.6.0'
22
+ spec.add_dependency 'cancancan'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.7'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ end
@@ -0,0 +1,10 @@
1
+ module Grape
2
+ module CanCan
3
+ module Authorizer
4
+ # Convienience method to authorize every route
5
+ def authorize_routes!
6
+ before { authorize_route! }
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ module Grape
2
+ module CanCan
3
+ module Helpers
4
+ delegate :can?, :cannot?, :authorize!, to: :current_ability
5
+
6
+ # Returns an instance of the CanCan ability
7
+ def current_ability
8
+ @current_ability ||= ::Ability.new(current_user)
9
+ end
10
+
11
+ # Call authorize using the :authorize key on the route
12
+ def authorize_route!
13
+ opts = env['api.endpoint'].options[:route_options]
14
+ return unless opts.key?(:authorize)
15
+ authorize!(*opts[:authorize])
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module Grape
2
+ module CanCan
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ require 'grape'
2
+ require 'grape/cancan/version'
3
+
4
+ module Grape
5
+ module CanCan
6
+ autoload :Helpers, 'grape/cancan/helpers'
7
+ autoload :Authorizer, 'grape/cancan/authorizer'
8
+
9
+ Grape::Endpoint.send :include, Grape::CanCan::Helpers
10
+ Grape::API.extend Grape::CanCan::Authorizer
11
+ end
12
+ end
@@ -0,0 +1 @@
1
+ require 'grape/cancan'
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grape-cancan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ray Zane
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grape
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: cancancan
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
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
+ description: Authorize your Grape API with CanCan
70
+ email:
71
+ - raymondzane@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - grape-cancan.gemspec
82
+ - lib/grape-cancan.rb
83
+ - lib/grape/cancan.rb
84
+ - lib/grape/cancan/authorizer.rb
85
+ - lib/grape/cancan/helpers.rb
86
+ - lib/grape/cancan/version.rb
87
+ homepage: https://github.com/rzane/grape-cancan
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Authorize your Grape API with CanCan
111
+ test_files: []