Class: CanTango::Ability::Base

Inherits:
Object
  • Object
show all
Includes:
CanCan::Ability, Rules
Defined in:
lib/cantango/ability/base.rb

Direct Known Subclasses

Executor::Base

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Rules

#calculate_rules, #clear_rules!, #default_rules, #normalize_rules!, #rules

Constructor Details

#initialize(candidate, options = {}) ⇒ Base

Equivalent to a CanCan Ability#initialize call which executes all the permission logic



11
12
13
14
15
# File 'lib/cantango/ability/base.rb', line 11

def initialize candidate, options = {}
  raise "Candidate must be something!" if !candidate
  @candidate, @options = candidate, options
  execute
end

Instance Attribute Details

#candidateObject (readonly)

Returns the value of attribute candidate.



7
8
9
# File 'lib/cantango/ability/base.rb', line 7

def candidate
  @candidate
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/cantango/ability/base.rb', line 7

def options
  @options
end

Instance Method Details

#executeObject



17
18
19
20
# File 'lib/cantango/ability/base.rb', line 17

def execute
  clear_rules!
  calculate_rules
end

#sessionObject



22
23
24
# File 'lib/cantango/ability/base.rb', line 22

def session
  @session ||= options[:session] || {} # seperate session cache for each type of user?
end