Sha256: d150c014e3f2093908aaf5d3932d7cf9e6dd1e0443e2aa1cf9d9f6b2d578bdf9

Contents?: true

Size: 1 KB

Versions: 13

Compression:

Stored size: 1 KB

Contents

# == Schema Information
#
# Table name: roles
#
#  id           :integer          not null, primary key
#  name         :string(255)      not null
#  display_name :string(255)
#  note         :text
#  created_at   :datetime
#  updated_at   :datetime
#  score        :integer          default(0), not null
#  position     :integer
#

class Role < ActiveRecord::Base
  attr_accessible :name, :display_name, :note
  include MasterModel
  default_scope :order => "roles.position"
  has_many :user_has_roles
  has_many :users, :through => :user_has_roles
  after_save :clear_all_cache
  after_destroy :clear_all_cache

  extend FriendlyId
  friendly_id :name

  def localized_name
    display_name.localize
  end

  def self.all_cache
    if Rails.env == 'production'
      Rails.cache.fetch('role_all'){Role.select(:name).all}
    else
      Role.select(:name)
    end
  end

  def clear_all_cache
    Rails.cache.delete('role_all')
  end

  def self.default_role
    Rails.cache.fetch('default_role'){Role.find('Guest')}
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
enju_leaf-1.1.0.rc11 app/models/role.rb
enju_leaf-1.1.0.rc10 app/models/role.rb
enju_leaf-1.1.0.rc9 app/models/role.rb
enju_leaf-1.1.0.rc8 app/models/role.rb
enju_leaf-1.1.0.rc7 app/models/role.rb
enju_leaf-1.1.0.rc6 app/models/role.rb
enju_leaf-1.1.0.rc5 app/models/role.rb
enju_leaf-1.1.0.rc4 app/models/role.rb
enju_leaf-1.1.0.rc3 app/models/role.rb
enju_leaf-1.1.0.rc2 app/models/role.rb
enju_leaf-1.1.0.rc1 app/models/role.rb
enju_leaf-1.1.0.beta3 app/models/role.rb
enju_leaf-1.1.0.pre3 app/models/role.rb