lib/authority/abilities.rb in authority-2.6.0 vs lib/authority/abilities.rb in authority-2.7.0
- old
+ new
@@ -15,16 +15,17 @@
# Set the default authorizer for this model.
# - Look for an authorizer named like the model inside the model's namespace.
# - If there is none, use 'ApplicationAuthorizer'
self.authorizer_name = begin
- "#{base.name}Authorizer".constantize.name
- rescue NameError => e
- "ApplicationAuthorizer"
- end
+ "#{base.name}Authorizer".constantize.name
+ rescue NameError => e
+ "ApplicationAuthorizer"
+ end
end
+
def authorizer
self.class.authorizer.new(self) # instantiate on every check, in case model has changed
end
module Definitions
@@ -38,18 +39,23 @@
include Definitions
module ClassMethods
include Definitions
+ def authorizer=(authorizer_class)
+ @authorizer = authorizer_class
+ self.authorizer_name = @authorizer.name
+ end
+
# @return [Class] of the designated authorizer
def authorizer
@authorizer ||= authorizer_name.constantize # Get an actual reference to the authorizer class
rescue NameError
raise Authority::NoAuthorizerError.new(
- "#{authorizer_name} is set as the authorizer for #{self}, but the constant is missing"
- )
+ "#{authorizer_name} is set as the authorizer for #{self}, but the constant is missing"
+ )
end
end
end
-end
+end
\ No newline at end of file