johnsbrn-has_permission 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 5
2
+ :patch: 6
3
3
  :major: 0
4
4
  :minor: 2
@@ -0,0 +1,39 @@
1
+ module ActionController
2
+ module Has
3
+ module Permission
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def requires_permission(*args)
11
+ options = args.extract_options!
12
+ args.each do |target|
13
+ self.class_eval <<-_RUBY
14
+ def #{target}_with_permission
15
+ klass = #{options[:class] || "controller_name.classify.constantize"}
16
+ klass.with_permission(current_user).can_#{target}? || #{options[:access_denied] || "access_denied"}
17
+ #{target}_without_permission
18
+ end
19
+ _RUBY
20
+ alias_method_chain target, "permission"
21
+ end
22
+ end
23
+
24
+ def permission_method_chain(*args)
25
+ args.each do |target|
26
+ self.class_eval <<-_RUBY
27
+ def #{target}_with_permission
28
+ #{target}_without_permission.with_permission(current_user)
29
+ end
30
+ _RUBY
31
+ alias_method_chain target, "permission"
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: johnsbrn-has_permission
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Johnson