Module: Authority::UserAbilities

Defined in:
lib/authority/user_abilities.rb

Instance Method Summary collapse

Instance Method Details

#can?(action, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/authority/user_abilities.rb', line 20

def can?(action, options = {})
  self_and_maybe_options = [self, options].tap {|args| args.pop if args.last == {}}
  begin
    ApplicationAuthorizer.send("authorizes_to_#{action}?", *self_and_maybe_options)
  rescue NoMethodError => original_exception
    begin
      # For backwards compatibility
      response = ApplicationAuthorizer.send("can_#{action}?", *self_and_maybe_options)
      Authority.logger.warn(
        "DEPRECATION WARNING: Please rename `ApplicationAuthorizer.can_#{action}?` to `authorizes_to_#{action}?`"
      )
      response
    rescue NoMethodError => new_exception
      raise original_exception
    end
  end
end