davydovanton / kan

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

Allow to use role classes, not only blocks #17

Closed davydovanton closed 6 years ago

davydovanton commented 6 years ago

We need to add ability to extract role logic to classes. Something like this:

module Post
  module Roles
    class Anonymous
      def call(user, _)
        user.id.nil?
      end
    end
  end

  class AnonymousAbilities
    include Kan::Abilities

    role :anonymous, Roles::Anonymous

    register(:read, :edit, :delete) { false }
  end
end
davydovanton commented 6 years ago

completed by https://github.com/davydovanton/kan/pull/18