Sha256: 9f90580a1b573cc0f28efcc6b5487787a436a57f6d202cde2a40faea3d4ad0d2

Contents?: true

Size: 844 Bytes

Versions: 2

Compression:

Stored size: 844 Bytes

Contents

module DoubleAuthEngine
  module UserMixin
    def self.included(base)
      base.class_eval do
        acts_as_authentic
        validates :email, :name, :presence => true
        validates :name, :length => { :maximum => 100 }
        has_many :assignments
        has_many :roles, :through => :assignments
      end
      base.send :extend, ClassMethods
      base.send :include, InstanceMethods
    end

    module ClassMethods
    end

    module InstanceMethods
      def email=(value)
        write_attribute :email, (value ? value.downcase : nil)
      end

      def deliver_password_reset_instructions!
        reset_perishable_token!
        Notifier.password_reset_instructions(self).deliver
      end

      def role_symbols
        roles.map do |role|
          role.name.underscore.to_sym
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
double_auth_engine-0.0.5 lib/double_auth_engine/models/user_mixin.rb
double_auth_engine-0.0.4 lib/double_auth_engine/models/user_mixin.rb