README.md in encrypted_search_attributes-1.0.1 vs README.md in encrypted_search_attributes-1.1.0

- old
+ new

@@ -1,15 +1,17 @@ # EncryptedSearchAttributes Auto populates encrypted fields that are designed for searching -Encrypting a field makes it very difficult to perform a case insensitive search for the columns data. This gem normalizes the text before encrypted it and storing it in a search column. The current normalization method is to convert the text to all lowercase. +Encrypting a field makes it very difficult to perform a case insensitive search for the columns data. This gem normalizes the text before encrypted it and storing it in a search column. The default normalization method is to convert the text to all lowercase, but you can specify your own normalization method. This gem is intended to be used with the symmetric-encryption gem. It assumes that a `encrypted_search_attribute` column exists for the encrypted attribute. -## Example +## Examples +### Using the default normalization method + Let's assume we have the following ActiveRecord model defined. ```ruby class Widget < ActiveRecord::Base attr_encrypted :name @@ -24,10 +26,42 @@ t.string "encrypted_name" t.string "encrypted_search_name" end ``` +### Specifying a custom normalization method + +You can specify custom normalizations in a couple of different ways + +#### Procs + +You can specify a proc that gets called to perform the normalization. This works well if you only have one field that you need to override the normalization for. + +```ruby +class Widget < ActiveRecord::Base + attr_encrypted :name + attr_encrypted_search :name, + normalize: ->(unencrypted_value) { enencrypted_value.to_s.downcase.gsub('.', '') } +end +``` + +#### Symbol referencing a method + +```ruby +class Widget < ActiveRecord::Base + attr_encrypted :name + attr_encrypted_search :name, + normalize: :normalize_search_value + + private + + def normalize_search_value(unencypted_value) + enencrypted_value.to_s.downcase.gsub('.', '') + end +end +``` + ## Installation Add this line to your application's Gemfile: gem 'encrypted_search_attributes' @@ -38,16 +72,12 @@ Or install it yourself as: $ gem install encrypted_search_attributes -## Usage - -TODO: Write usage instructions here - ## Contributing -1. Fork it ( http://github.com/mscottford/encrypted_search_attributes/fork ) +1. Fork it ( http://github.com/corgibytes/encrypted_search_attributes/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request