Class: CanTango::Ability::Cache::Key
- Inherits:
-
Object
- Object
- CanTango::Ability::Cache::Key
- Defined in:
- lib/cantango/ability/cache/key.rb
Instance Attribute Summary collapse
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(user, subject) ⇒ Key
constructor
A new instance of Key.
- #same?(session) ⇒ Boolean
- #value ⇒ Object
Constructor Details
#initialize(user, subject) ⇒ Key
Returns a new instance of Key.
7 8 9 10 |
# File 'lib/cantango/ability/cache/key.rb', line 7 def initialize user, subject @user = user @subject = subject end |
Instance Attribute Details
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
5 6 7 |
# File 'lib/cantango/ability/cache/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/key.rb', line 5 def user @user end |
Instance Method Details
#same?(session) ⇒ Boolean
17 18 19 20 |
# File 'lib/cantango/ability/cache/key.rb', line 17 def same? session raise "No session available" if !session session[:cache_key] && (value == session[:cache_key].value) end |
#value ⇒ Object
12 13 14 15 |
# File 'lib/cantango/ability/cache/key.rb', line 12 def value raise "#{user.class} must have a method ##{user_key_field}. You can configure this with CanTango.config#user.unique_key_field" if !user.respond_to?(user_key_field) @value ||= [user_key, subject_roles_hash].hash end |