Module: Capable::ActsAsCapable::InstanceMethods

Defined in:
lib/acts_as_capable.rb

Instance Method Summary collapse

Instance Method Details

#ability_arrayObject



29
30
31
32
33
34
35
36
37
38
39
40
# 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) ⇒ Object



50
51
52
# 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) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
# 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) ⇒ Object



54
55
56
57
58
59
# 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