Class: Account

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/orats/templates/includes/new/rails/app/models/account.rb

Constant Summary collapse

ROLES =
%w[admin guest]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate_password(length = 10) ⇒ Object



22
23
24
# File 'lib/orats/templates/includes/new/rails/app/models/account.rb', line 22

def self.generate_password(length = 10)
  Devise.friendly_token.first(length)
end

.serialize_from_session(key, salt) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/orats/templates/includes/new/rails/app/models/account.rb', line 13

def self.serialize_from_session(key, salt)
  # store the current_account in the cache so we do not perform a db lookup on each authenticated page
  single_key = key.is_a?(Array) ? key.first : key

  Rails.cache.fetch("account:#{single_key}") do
    Account.where(id: single_key).entries.first
  end
end

Instance Method Details

#is?(role_check) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/orats/templates/includes/new/rails/app/models/account.rb', line 26

def is?(role_check)
  role.to_sym == role_check
end