Sha256: df81cbf7c737e31460e6469efa5043495ef7408da442f596024214a0da7833a8

Contents?: true

Size: 1.73 KB

Versions: 19

Compression:

Stored size: 1.73 KB

Contents

#!/usr/bin/env ruby
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

19 entries across 19 versions & 1 rubygems

Version Path
rtt-0.0.0.47 lib/rtt/user.rb
rtt-0.0.0.46 lib/rtt/user.rb
rtt-0.0.0.45 lib/rtt/user.rb
rtt-0.0.0.44 lib/rtt/user.rb
rtt-0.0.0.43 lib/rtt/user.rb
rtt-0.0.0.42 lib/rtt/user.rb
rtt-0.0.0.41 lib/rtt/user.rb
rtt-0.0.0.39 lib/rtt/user.rb
rtt-0.0.0.38 lib/rtt/user.rb
rtt-0.0.0.37 lib/rtt/user.rb
rtt-0.0.0.36 lib/rtt/user.rb
rtt-0.0.0.35 lib/rtt/user.rb
rtt-0.0.0.33 lib/rtt/user.rb
rtt-0.0.0.32 lib/rtt/user.rb
rtt-0.0.0.31 lib/rtt/user.rb
rtt-0.0.0.28 lib/rtt/user.rb
rtt-0.0.0.27 lib/rtt/user.rb
rtt-0.0.0.26 lib/rtt/user.rb
rtt-0.0.0.25 lib/rtt/user.rb