Module: DeviseMasquerade::Models::Masqueradable::ClassMethods

Defined in:
lib/devise_masquerade/models/masqueradable.rb

Instance Method Summary collapse

Instance Method Details

#cache_masquerade_key_by(key) ⇒ Object



19
20
21
# File 'lib/devise_masquerade/models/masqueradable.rb', line 19

def cache_masquerade_key_by(key)
  "#{self.name.pluralize.underscore}:#{key}:masquerade"
end

#find_by_masquerade_key(key) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/devise_masquerade/models/masqueradable.rb', line 27

def find_by_masquerade_key(key)
  id = ::Rails.cache.read(cache_masquerade_key_by(key))

  # clean up the cached masquerade key value
  remove_masquerade_key!(key)

  where(id: id).first
end

#remove_masquerade_key!(key) ⇒ Object



23
24
25
# File 'lib/devise_masquerade/models/masqueradable.rb', line 23

def remove_masquerade_key!(key)
  ::Rails.cache.delete(cache_masquerade_key_by(key))
end