module Capable::ActsAsCapable::InstanceMethods

Public Instance Methods

ability_array() click to toggle source
# File lib/acts_as_capable.rb, line 29
def ability_array
  if self.respond_to? :ability_list
    if self.ability_list.present?
      return self.ability_list.split(",")
    else
      return Array.new
    end
  else
    puts "CAPABLE_WARNING: It is recommended to create the string 'ability_list' for the class '#{self.class.name}' in order to speed up ability checking" if Capable.configuration[:verbose]
    return self.abilities.pluck(:ability).uniq
  end
end
assign_ability(ability, active=true, expires_at=nil, renewer=nil) click to toggle source
# File lib/acts_as_capable.rb, line 50
def assign_ability(ability, active=true, expires_at=nil, renewer=nil)
  Capability.create_capability(self, ability, active, expires_at, renewer)
end
has_ability?(ability) click to toggle source
# File lib/acts_as_capable.rb, line 42
def has_ability?(ability)
  if ability.kind_of? String
    return ability_array.include? ability
  else
    return ability_array.include? ability.ability
  end
end
unassign_ability(ability, renewer=nil) click to toggle source
# File lib/acts_as_capable.rb, line 54
def unassign_ability(ability, renewer=nil)
  Capability.where(capable: self, ability: ability, renewer: renewer, active: true).each do |capability|
    capability.active = false
    capability.save # This will kickoff the update logic
  end
end