johnsbrn-has_permission 0.2.5 → 0.2.6
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.
- data/VERSION.yml +1 -1
- data/lib/action_controller/has/permission.rb +39 -0
- metadata +1 -1
data/VERSION.yml
CHANGED
@@ -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
|