lib/authority/abilities.rb in authority-2.4.3 vs lib/authority/abilities.rb in authority-2.5.0

- old
+ new

@@ -9,13 +9,20 @@ module Abilities extend ActiveSupport::Concern extend Forwardable - # Assume authorizer is `ApplicationAuthorizer` (but let the user change that) - included do + included do |base| class_attribute :authorizer_name - self.authorizer_name = "ApplicationAuthorizer" + + # 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 end def authorizer self.class.authorizer.new(self) # instantiate on every check, in case model has changed end