Sha256: 19f37bf93cfad6ae17f7114d3fae52511bb37e40c369a4ba1b79610cd18e7dc1
Contents?: true
Size: 1.73 KB
Versions: 16
Compression:
Stored size: 1.73 KB
Contents
#!/usr/bin/ruby -w module Rtt class User include DataMapper::Resource BLANK_FIELD = '' DEFAULT_NICK = 'Default user' property :id, Serial property :nickname, String, :required => true, :unique => true, :default => DEFAULT_NICK property :first_name, String, :default => BLANK_FIELD property :last_name, String, :default => BLANK_FIELD property :company, String, :default => BLANK_FIELD property :address, String, :default => BLANK_FIELD property :city, String, :default => BLANK_FIELD property :country, String, :default => BLANK_FIELD property :email, String, :default => BLANK_FIELD property :phone, String, :default => BLANK_FIELD property :zip, String, :default => BLANK_FIELD property :site, String, :default => BLANK_FIELD property :active, Boolean, :default => false has n, :tasks #, :through => Resource has n, :projects, :through => :tasks def self.default first_or_create :active => true end def self.find_or_create_active last_user = User.last if last_user.present? last_user.active = true last_user.save last_user else self.default end end def activate self.active = true self.save self end def deactivate self.active = false self.save self end def full_name "#{first_name.present? ? first_name : ''} #{last_name.present? ? last_name : ''}".strip end def full_name_and_nickname "#{full_name.present? ? full_name : ''} #{full_name.present? ? "(#{nickname})" : nickname }".strip end def location "#{self.city}#{self.city.present? && self.country.present? ? ', ' : ''}#{self.country}".strip end end end
Version data entries
16 entries across 16 versions & 1 rubygems