5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/rolypoly/controller_role_dsl.rb', line 5
def self.included(sub)
sub.before_filter(:rolypoly_check_role_access!) if sub.respond_to? :before_filter
if sub.respond_to? :rescue_from
sub.rescue_from(FailedRoleCheckError) do
respond_to do |f|
f.html { render text: "Not Authorized", status: 401 }
f.json { render json: { error: "Not Authorized" }, status: 401 }
f.xml { render xml: { error: "Not Authorized" }, status: 401 }
end
end
end
unless sub.method_defined? :current_roles
define_method(:current_roles) { [] }
end
sub.send :extend, ClassMethods
sub.class_eval do
define_singleton_method :inherited do |sub|
super sub
sub.instance_variable_set(:@rolypoly_gatekeepers, rolypoly_gatekeepers.map(&:clone))
end
end
end
|