davydovanton / kan

Simple, functional authorization library and role management for ruby
http://www.kanrb.org
MIT License
232 stars 12 forks source link

Renamed ambiguous ArgumentError to MissingScopeError when scope is mi… #45

Closed renius closed 4 years ago

renius commented 4 years ago

…ssing in ability

Hi!

I want to be able to have something less ambiguous than ArgumentError. 1) to separate kan errors from others 2) to catch it more accurately

ability = Kan::Application.new(
      user: UserAbilities.new,
      post: PostAbilities.new
    )

def is_it_possible?
  %i[user post unmanaged].sample do |resource| 
    ability[[resource, action].join('.')].call(alien, _)
  end
rescue MissingScopeError
  default_rule
end

Best, Anton