Sha256: d240681b99fc8252d3357886bf514c15837b1e250cea822832dc6d8f0857468b

Contents?: true

Size: 765 Bytes

Versions: 7

Compression:

Stored size: 765 Bytes

Contents

class UcbRails::User < ActiveRecord::Base
  self.table_name = 'users'
  
  attr_accessible :uid, :first_name, :last_name, :inactive
  
  before_validation :set_first_last_name
  
  # Overridden by application
  def roles
    []
  end
  
  def has_role?(role)
    admin? || roles.include?(role)
  end
  
  def active?
    !inactive?
  end
  
  def admin!(_admin=true)
    update_attribute(:admin, _admin)
  end
  
  def inactive!(_inactive=true)
    update_attribute(:inactive, _inactive)
  end
  
  def self.active
    where(inactive: false)
  end
  
  def self.admin
    where(admin: true)
  end
  
  private
  
  def set_first_last_name
    self.first_last_name = [first_name, last_name]
      .select { |n| n.present? }
      .join(' ')
      .presence
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ucb_rails-0.0.13 app/models/ucb_rails/user.rb
ucb_rails-0.0.12 app/models/ucb_rails/user.rb
ucb_rails-0.0.11 app/models/ucb_rails/user.rb
ucb_rails-0.0.10 app/models/ucb_rails/user.rb
ucb_rails-0.0.9 app/models/ucb_rails/user.rb
ucb_rails-0.0.8 app/models/ucb_rails/user.rb
ucb_rails-0.0.7 app/models/ucb_rails/user.rb