Class: CanTango::Ability::Cache::SimpleKey
- Inherits:
-
Object
- Object
- CanTango::Ability::Cache::SimpleKey
- Defined in:
- lib/cantango/ability/cache/simple_key.rb
Instance Attribute Summary collapse
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(user, subject = nil) ⇒ SimpleKey
constructor
FIX: do we really need both user and subject? how about just candidate!.
- #to_s ⇒ Object
- #value ⇒ Object
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
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
5 6 7 |
# File 'lib/cantango/ability/cache/simple_key.rb', line 5 def subject @subject end |
#user ⇒ Object (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_s ⇒ Object
22 23 24 |
# File 'lib/cantango/ability/cache/simple_key.rb', line 22 def to_s "key hash: #{value}" end |
#value ⇒ Object
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 |