Sha256: 473aa392d20b7175fc20d6381110689b029d07a917193e6b9821f27a992e498e

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

module Symphonia
  module UserManagement

    extend ActiveSupport::Concern

    included do

      enum status: { active: 1, pending: 5, archived: 9 }

      scope :sorted, -> { order(:first_name, :last_name) }

      # validates :mail, uniqueness: true, format: { with: Authlogic::Regex::EMAIL_NONASCII }
      # validates :password, presence: true, if: ->(u){ u.new_record? }

      validates :login, :mail, :first_name, :last_name, presence: true

      def self.current=(entity)
        Rails.logger.info("* #{entity.class.name}: #{entity.login} id: #{entity.id}") if entity
        Thread.current[:"current_#{name.underscore}"] = entity
      end

      def self.current
        Thread.current[:"current_#{name.underscore}"] ||= "#{self}::Anonymous".constantize.new
      end

      def name
        "#{first_name} #{last_name}"
      end

      def name=(string)
        self.first_name, self.last_name = string.split(" ")
      end

      def status_new?
        pending?
      end

      def lock?
        !active?
      end

      alias_method :archive?, :lock?

      def archive!
        archived!
      end

      def unarchive!
        active!
      end

      alias_method :activate!, :unarchive!

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
symphonia-3.0.3 lib/symphonia/user_management.rb
symphonia-3.0.2 lib/symphonia/user_management.rb
symphonia-3.0.1 lib/symphonia/user_management.rb
symphonia-3.0.0 lib/symphonia/user_management.rb