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.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(user, subject = nil, method_names = nil) ⇒ Key
constructor
A new instance of Key.
- #method_names ⇒ Object
- #same?(session) ⇒ Boolean
- #to_s ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(user, subject = nil, method_names = nil) ⇒ Key
Returns a new instance of Key.
7 8 9 10 11 |
# File 'lib/cantango/ability/cache/key.rb', line 7 def initialize user, subject = nil, method_names = nil @user = user @subject = subject || user @method_names = method_names if method_names 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 |
Class Method Details
.create_for(ability) ⇒ Object
17 18 19 |
# File 'lib/cantango/ability/cache/key.rb', line 17 def self.create_for ability self.new ability.user, ability.subject end |
Instance Method Details
#method_names ⇒ Object
13 14 15 |
# File 'lib/cantango/ability/cache/key.rb', line 13 def method_names @method_names ||= [:roles_list, :role_groups_list] end |
#same?(session) ⇒ Boolean
26 27 28 29 |
# File 'lib/cantango/ability/cache/key.rb', line 26 def same? session raise "No session available" if !session session[:cache_key] && (value == session[:cache_key].value) end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/cantango/ability/cache/key.rb', line 31 def to_s "key hash: #{value}" end |
#value ⇒ Object
21 22 23 24 |
# File 'lib/cantango/ability/cache/key.rb', line 21 def value raise "No key could be generated for User:#{user.inspect} and Subject:#{subject} - key field: #{user_key_field}" if hash_values.empty? @value ||= hash_values.hash end |