lib/authority/abilities.rb in authority-2.5.0 vs lib/authority/abilities.rb in authority-2.6.0
- old
+ new
@@ -7,11 +7,10 @@
# in order to make that possible.
# All delegate to the methods of the same name on the model's authorizer.
module Abilities
extend ActiveSupport::Concern
- extend Forwardable
included do |base|
class_attribute :authorizer_name
# Set the default authorizer for this model.
@@ -26,21 +25,21 @@
def authorizer
self.class.authorizer.new(self) # instantiate on every check, in case model has changed
end
- # Send all calls like `editable_by?` to an authorizer instance
- Authority.adjectives.each do |adjective|
- def_delegators :authorizer, :"#{adjective}_by?"
+ module Definitions
+ # Send all calls like `editable_by?` to an authorizer instance
+ # Not using Forwardable because it makes it harder for users to track an ArgumentError
+ # back to their authorizer
+ Authority.adjectives.each do |adjective|
+ define_method("#{adjective}_by?") { |*args| authorizer.send("#{adjective}_by?", *args) }
+ end
end
+ include Definitions
module ClassMethods
- extend Forwardable
-
- # Send all calls like `editable_by?` to the authorizer class
- Authority.adjectives.each do |adjective|
- def_delegators :authorizer, :"#{adjective}_by?"
- end
+ include Definitions
# @return [Class] of the designated authorizer
def authorizer
@authorizer ||= authorizer_name.constantize # Get an actual reference to the authorizer class
rescue NameError