padrino-cancan 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ require 'cancan'
2
+ require 'padrino-cancan/helpers'
3
+
4
+ module Padrino
5
+ module CanCan
6
+ class << self
7
+ def registered(app)
8
+ app.helpers Padrino::CanCan::Helpers
9
+ # app.helpers ::CanCan::ControllerAdditions
10
+ end
11
+ alias :included :registered
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,61 @@
1
+ module Padrino
2
+ module CanCan
3
+ module Helpers
4
+ def current_ability
5
+ @ability ||= Ability.new(current_account, registered_abilities)
6
+ end
7
+
8
+ def can? *args
9
+ current_ability.can? *args
10
+ end
11
+
12
+ def cannot? *args
13
+ current_ability.cannot? *args
14
+ end
15
+
16
+ def authorize! *args
17
+ current_ability.authorize! *args
18
+ end
19
+
20
+ def registered_abilities
21
+ self.class.registered_abilities
22
+ end
23
+
24
+ module ClassMethods
25
+ def registered_abilities
26
+ @@_registered_abilities ||= {}
27
+ end
28
+
29
+ def role roles, &block
30
+ if roles.is_a? Array
31
+ roles.each do |role| allow_role role, &block end
32
+ else
33
+ allow_role roles, &block
34
+ end
35
+ end
36
+
37
+ private
38
+ def allow_role role, &block
39
+ registered_abilities[role] ||= []
40
+ registered_abilities[role] << block
41
+ end
42
+ end
43
+
44
+ def self.included(base) #:nodoc:
45
+ base.extend(ClassMethods)
46
+ end
47
+ end
48
+
49
+ class Ability
50
+ include ::CanCan::Ability
51
+
52
+ def initialize account, registered_abilities
53
+ role = account.role.to_sym rescue :any
54
+
55
+ (registered_abilities[role] || []).each do |cans|
56
+ instance_eval &cans
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: padrino-cancan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Phil Pirozhkov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-13 00:00:00.000000000 +04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: cancan
17
+ requirement: &69782600 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *69782600
26
+ description: Padrino can can use all CanCan goodies
27
+ email:
28
+ - pirj@mail.ru
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/padrino-cancan.rb
34
+ - lib/padrino-cancan/helpers.rb
35
+ has_rdoc: true
36
+ homepage: https://github.com/pirj/padrino-cancan
37
+ licenses: []
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 1.6.2
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Padrino can can use all CanCan goodies
60
+ test_files: []