Sha256: 4ddf5b37d63a685d6577a0c773f7a6e67e785d8c9c17e260bb08cb4b6cd54303

Contents?: true

Size: 1 KB

Versions: 75

Compression:

Stored size: 1 KB

Contents

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

# == 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
#

Version data entries

75 entries across 75 versions & 5 rubygems

Version Path
enju_subject-0.1.0.pre spec/dummy/app/models/role.rb
enju_export-0.1.0 spec/dummy/app/models/role.rb
enju_export-0.0.3 spec/dummy/app/models/role.rb
enju_resource_merge-0.0.17 spec/dummy/app/models/role.rb
enju_subject-0.0.18 spec/dummy/app/models/role.rb
enju_subject-0.0.17 spec/dummy/app/models/role.rb
enju_export-0.0.2 spec/dummy/app/models/role.rb
enju_resource_merge-0.0.16 spec/dummy/app/models/role.rb
enju_resource_merge-0.0.15 spec/dummy/app/models/role.rb
enju_subject-0.0.16 spec/dummy/app/models/role.rb
enju_export-0.0.1 spec/dummy/app/models/role.rb
enju_resource_merge-0.0.14 spec/dummy/app/models/role.rb
enju_resource_merge-0.0.13 spec/dummy/app/models/role.rb
enju_resource_merge-0.0.12 spec/dummy/app/models/role.rb
enju_resource_merge-0.0.11 spec/dummy/app/models/role.rb