Sha256: b8e1d8708fb6e6b9d4a7c4ee448f72b04a4b913e761be2335ecaf8a55129f64d

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

module AuthHelpers
  # Helpers to migration:
  #
  #   create_table :accounts do |t|
  #     t.extend AuthHelpers::Migration
  #     
  #     t.authenticable
  #     t.confirmable
  #     t.recoverable
  #     t.rememberable
  #     t.timestamps
  #   end
  #
  # However this method does not add indexes. If you need them, here is the declaration:
  #
  #   add_index "accounts", ["email"],               :name => "email",               :unique => true
  #   add_index "accounts", ["token"],               :name => "token",               :unique => true
  #   add_index "accounts", ["confirmation_code"],   :name => "confirmation_code",   :unique => true
  #   add_index "accounts", ["reset_password_code"], :name => "reset_password_code", :unique => true
  #
  # E-mail index should be slightly changed with you are working with polymorphic
  # associations.
  #
  module Migration

    # Creates email, hashed_password and salt.
    #
    def authenticable
      self.string :email,           :limit => 100, :null => false, :default => ''
      self.string :hashed_password, :limit =>  40, :null => false, :default => ''
      self.string :salt,            :limit =>  10, :null => false, :default => ''
    end

    # Creates confirmation_code, confirmed_at and confirmation_sent_at.
    #
    def confirmable
      self.string   :confirmation_code, :limit =>  40, :null => true
      self.datetime :confirmed_at
      self.datetime :confirmation_sent_at
    end

    # Creates reset_password_code.
    #
    def recoverable
      self.string :reset_password_code, :limit =>  40, :null => true
    end

    # Creates token and token_created_at.
    #
    def rememberable
      self.string   :token, :limit =>  40, :null => true
      self.datetime :token_expires_at
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
josevalim-auth_helpers-0.1.0 lib/auth_helpers/migration.rb
josevalim-auth_helpers-0.1.1 lib/auth_helpers/migration.rb
josevalim-auth_helpers-0.1.2 lib/auth_helpers/migration.rb