Class: CanTango::Ability::Cache::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/cantango/ability/cache/key.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, subject = nil) ⇒ Key

Returns a new instance of Key.



7
8
9
10
# File 'lib/cantango/ability/cache/key.rb', line 7

def initialize user, subject = nil
  @user = user
  @subject = subject || user
end

Instance Attribute Details

#subjectObject (readonly)

Returns the value of attribute subject.



5
6
7
# File 'lib/cantango/ability/cache/key.rb', line 5

def subject
  @subject
end

#userObject (readonly)

Returns the value of attribute user.



5
6
7
# File 'lib/cantango/ability/cache/key.rb', line 5

def user
  @user
end

Class Method Details

.create_for(ability) ⇒ Object



12
13
14
# File 'lib/cantango/ability/cache/key.rb', line 12

def self.create_for ability
  self.new ability.user, ability.subject
end

Instance Method Details

#same?(session) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/cantango/ability/cache/key.rb', line 21

def same? session
  raise "No session available" if !session
  session[:cache_key] && (value == session[:cache_key].value)
end

#valueObject



16
17
18
19
# File 'lib/cantango/ability/cache/key.rb', line 16

def value
  raise "No key could be generated for #{user} and #{subject}" if hash_values.empty?
  @value ||= hash_values.hash
end