grape-cancan 0.0.1 → 0.0.2

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: 38721406628690b22a71b1089852cf9817243d66
4
- data.tar.gz: 909778e00ac3260ab4b8e2756f47ca9073d54532
3
+ metadata.gz: 34714b17e347b036572b0167cf8a550319b4fbf7
4
+ data.tar.gz: 17667b2a66979de84ef5b36d3a312e7d5b1716bc
5
5
  SHA512:
6
- metadata.gz: a6facc9a56bc9889ed35589dcd11b3f3ff73296eeab18ad5d9a2416bcaf6e8c75c214daf52a0fd5dde1d8ba9fec9be673ec7ba65f695269f8a459f7475e43b47
7
- data.tar.gz: 35d2caf20054ad54f7a7618f0015792df7d88ba57231e7b4fc395915658f22dfc365bbed4c01110d181a2cb663ff74bcf2597be36e213524dd2445bd5ffab549
6
+ metadata.gz: 89c43f7809c5dff5fe1e56d30993f9216ba9be96397f9128d15aa8fdc308b54361c5b9677a4aa249b04533aaef85399dfa9f972684ea2e8b146ba4dcdcf585a4
7
+ data.tar.gz: f9855032826bc43bad8438fd5caf06e31cb5ff8b32361d82ede73113a92ac733bcb17f3331b9d253cea8202aeaa8697043c17ec94911021075c43f24c68292ed
data/README.md CHANGED
@@ -22,7 +22,7 @@ __NOTE:__ The [cancan](https://github.com/ryanb/cancan) gem by Ryan Bates is no
22
22
 
23
23
  ## Usage
24
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.
25
+ This gem adds the __current_ability__, __can?__, __cannot?__, and __authorize!__ helper methods to all Grape API endpoints. This gem expects you to have a __current_user__ helper.
26
26
 
27
27
  ```ruby
28
28
  class Users < Grape::API
@@ -3,10 +3,28 @@ require 'grape/cancan/version'
3
3
 
4
4
  module Grape
5
5
  module CanCan
6
- autoload :Helpers, 'grape/cancan/helpers'
7
- autoload :Authorizer, 'grape/cancan/authorizer'
6
+ module API
7
+ # Convienience method to authorize every route
8
+ def authorize_routes!
9
+ before { authorize_route! }
10
+ end
11
+ end
8
12
 
9
- Grape::Endpoint.send :include, Grape::CanCan::Helpers
10
- Grape::API.extend Grape::CanCan::Authorizer
13
+ module Endpoint
14
+ # Returns an instance of the CanCan ability
15
+ def current_ability
16
+ @current_ability ||= ::Ability.new(current_user)
17
+ end
18
+ delegate :can?, :cannot?, :authorize!, to: :current_ability
19
+
20
+ # Call authorize using the :authorize key on the route
21
+ def authorize_route!
22
+ opts = env['api.endpoint'].options[:route_options]
23
+ authorize!(*opts[:authorize]) if opts.key?(:authorize)
24
+ end
25
+ end
26
+
27
+ Grape::API.extend Grape::CanCan::API
28
+ Grape::Endpoint.send :include, Grape::CanCan::Endpoint
11
29
  end
12
30
  end
@@ -1,5 +1,5 @@
1
1
  module Grape
2
2
  module CanCan
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-cancan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ray Zane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-29 00:00:00.000000000 Z
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.6.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.6.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: cancancan
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.7'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.7'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '10.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
69
  description: Authorize your Grape API with CanCan
@@ -73,7 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - ".gitignore"
76
+ - .gitignore
77
77
  - Gemfile
78
78
  - LICENSE.txt
79
79
  - README.md
@@ -81,8 +81,6 @@ files:
81
81
  - grape-cancan.gemspec
82
82
  - lib/grape-cancan.rb
83
83
  - lib/grape/cancan.rb
84
- - lib/grape/cancan/authorizer.rb
85
- - lib/grape/cancan/helpers.rb
86
84
  - lib/grape/cancan/version.rb
87
85
  homepage: https://github.com/rzane/grape-cancan
88
86
  licenses:
@@ -94,12 +92,12 @@ require_paths:
94
92
  - lib
95
93
  required_ruby_version: !ruby/object:Gem::Requirement
96
94
  requirements:
97
- - - ">="
95
+ - - '>='
98
96
  - !ruby/object:Gem::Version
99
97
  version: '0'
100
98
  required_rubygems_version: !ruby/object:Gem::Requirement
101
99
  requirements:
102
- - - ">="
100
+ - - '>='
103
101
  - !ruby/object:Gem::Version
104
102
  version: '0'
105
103
  requirements: []
@@ -1,10 +0,0 @@
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
@@ -1,19 +0,0 @@
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