Sha256: 8285f3412a6407927735ceb0f25bed15a804f4d21fd8a19e713eee33e8110053

Contents?: true

Size: 980 Bytes

Versions: 251

Compression:

Stored size: 980 Bytes

Contents

class Role < ActiveRecord::Base
  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

251 entries across 251 versions & 8 rubygems

Version Path
enju_oai-0.1.0.pre10 spec/dummy/app/models/role.rb
enju_circulation-0.1.0.pre28 spec/dummy/app/models/role.rb
enju_biblio-0.1.0.pre41 spec/dummy/app/models/role.rb
enju_circulation-0.1.0.pre27 spec/dummy/app/models/role.rb
enju_flower-0.1.0.pre9 spec/dummy/app/models/role.rb
enju_circulation-0.1.0.pre26 spec/dummy/app/models/role.rb
enju_library-0.1.0.pre23 spec/dummy/app/models/role.rb
enju_biblio-0.1.0.pre40 spec/dummy/app/models/role.rb
enju_biblio-0.1.0.pre39 spec/dummy/app/models/role.rb
enju_flower-0.1.0.pre8 spec/dummy/app/models/role.rb
enju_biblio-0.1.0.pre38 spec/dummy/app/models/role.rb
enju_circulation-0.1.0.pre25 spec/dummy/app/models/role.rb
enju_flower-0.1.0.pre7 spec/dummy/app/models/role.rb
enju_circulation-0.1.0.pre24 spec/dummy/app/models/role.rb
enju_library-0.1.0.pre22 spec/dummy/app/models/role.rb
enju_biblio-0.1.0.pre37 spec/dummy/app/models/role.rb
enju_flower-0.1.0.pre6 spec/dummy/app/models/role.rb
enju_biblio-0.1.0.pre36 spec/dummy/app/models/role.rb
enju_biblio-0.1.0.pre35 spec/dummy/app/models/role.rb
enju_biblio-0.1.0.pre34 spec/dummy/app/models/role.rb