module Granted::Grantee

Public Instance Methods

grant(*rights) click to toggle source
# File lib/granted/modules/grantee.rb, line 4
def grant(*rights)
  Granted::Granter.new
                  .grant
                  .rights(rights)
                  .to(self)
end
grants_for(subject) click to toggle source
# File lib/granted/modules/grantee.rb, line 18
def grants_for(subject)
  grants.subject(subject).map do |g|
    grant_class_name_to_symbol(g.type)
  end.sort
end
revoke(*rights) click to toggle source
# File lib/granted/modules/grantee.rb, line 11
def revoke(*rights)
  Granted::Granter.new
                  .revoke
                  .rights(rights)
                  .to(self)
end

Private Instance Methods

grant_class_name_to_symbol(c) click to toggle source
# File lib/granted/modules/grantee.rb, line 26
def grant_class_name_to_symbol(c)
  # A class name could be Granted::ReadGrant
  # and we want to make :read out of it
  c.underscore[8..-1]  # Remove granted/ prefix
   .chomp('_grant')    # Remove trailing _grant
   .to_sym
end