Class: CanTango::Ability::Cache::SimpleKey

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, subject = nil) ⇒ SimpleKey

FIX: do we really need both user and subject? how about just candidate!



8
9
10
11
# File 'lib/cantango/ability/cache/simple_key.rb', line 8

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/simple_key.rb', line 5

def subject
  @subject
end

#userObject (readonly)

Returns the value of attribute user.



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

def user
  @user
end

Class Method Details

.create_for(ability) ⇒ Object



13
14
15
# File 'lib/cantango/ability/cache/simple_key.rb', line 13

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

Instance Method Details

#to_sObject



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

def to_s
  "key hash: #{value}"
end

#valueObject



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

def value
  raise "No key could be generated for User:#{user.inspect} and Subject:#{subject} - key field: #{user_key_field}" if !user_key
  @value ||= user_key.hash
end