Sha256: cdfb646778a206e540f41683a29b122bc37306c05468982d966d64b8e0f42bbf

Contents?: true

Size: 897 Bytes

Versions: 1

Compression:

Stored size: 897 Bytes

Contents

require 'janus/hooks/trackable'

module Janus
  module Models
    # = Trackable
    #
    # Simple hook to update some columns of your model whenever a user logs in.
    #
    # == Required columns
    #
    # - +sign_in_count+
    # - +current_sign_in_ip+
    # - +current_sign_in_at+
    # - +last_sign_in_ip+
    # - +last_sign_in_at+
    #
    module Trackable
      extend ActiveSupport::Concern

      included do
        begin
          attr_protected :sign_in_count, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip, :last_sign_in_ip
        rescue
        end
      end

      def track!(ip)
        self.sign_in_count += 1

        self.last_sign_in_at = self.current_sign_in_at
        self.last_sign_in_ip = self.current_sign_in_ip

        self.current_sign_in_at = Time.now
        self.current_sign_in_ip = ip

        save(:validate => false)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
janus-0.7.0 lib/janus/models/trackable.rb