README.md in blind_index-2.0.2 vs README.md in blind_index-2.1.0

- old
+ new

@@ -24,17 +24,17 @@ ```ruby gem 'blind_index' ``` -## Getting Started +## Prep Your model should already be set up with Lockbox or attr_encrypted. The examples are for a `User` model with `encrypts :email` or `attr_encrypted :email`. See the full examples for [Lockbox](https://ankane.org/securing-user-emails-lockbox) and [attr_encrypted](https://ankane.org/securing-user-emails-in-rails) if needed. Also, if you use attr_encrypted, [generate a key](#key-generation). ---- +## Getting Started Create a migration to add a column for the blind index ```ruby add_column :users, :email_bidx, :string @@ -67,29 +67,51 @@ ```ruby User.where(email: "test@example.org") ``` +## Expressions + +You can apply expressions to attributes before indexing and searching. This gives you the the ability to perform case-insensitive searches and more. + +```ruby +class User < ApplicationRecord + blind_index :email, expression: ->(v) { v.downcase } +end +``` + ## Validations -To prevent duplicates, use: +You can use blind indexes for uniqueness validations. ```ruby class User < ApplicationRecord validates :email, uniqueness: true end ``` -We also recommend adding a unique index to the blind index column through a database migration. +We recommend adding a unique index to the blind index column through a database migration. -## Expressions +```ruby +add_index :users, :email_bidx, unique: true +``` -You can apply expressions to attributes before indexing and searching. This gives you the the ability to perform case-insensitive searches and more. +For `allow_blank: true`, use: ```ruby class User < ApplicationRecord + blind_index :email, expression: ->(v) { v.presence } + validates :email, uniqueness: {allow_blank: true} +end +``` + +For `case_sensitive: false`, use: + +```ruby +class User < ApplicationRecord blind_index :email, expression: ->(v) { v.downcase } + validates :email, uniqueness: true # for best performance, leave out {case_sensitive: false} end ``` ## Multiple Indexes @@ -434,5 +456,7 @@ git clone https://github.com/ankane/blind_index.git cd blind_index bundle install bundle exec rake test ``` + +For security issues, send an email to the address on [this page](https://github.com/ankane).