Sha256: 13447988a175d8e803bc8b92219ac310b9098389ec95f3da48e12823d5eee9b6

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 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}")
        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 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

1 entries across 1 versions & 1 rubygems

Version Path
symphonia-2.1.8 lib/symphonia/user_management.rb