f55b385

On May 9, 2014, at 11:17 AM, Fabio Kreusch <notifications@github.com> wrote:

> In lib/crypt_keeper/model.rb:
> 
> > @@ -80,6 +80,25 @@ def search_by_plaintext(field, criteria)
> >          end
> >        end
> >  
> > +      # Public: Encrypt a table for the first time.
> > +      def encrypt_table
> > +        enc       = encryptor_klass.new(crypt_keeper_options)
> > +        tmp_table = Class.new(ActiveRecord::Base).tap { |c| c.table_name = self.table_name }
> > +
> > +        transaction do
> > +          tmp_table.find_each do |r|
> > +            crypt_keeper_fields.each do |field|
> > +              plaintext = r[field]
> > +
> > +              if plaintext.present?
> > +                cipher_text = enc.encrypt(plaintext)
> > +                r.update_attributes!(field.to_sym => cipher_text)
> How about setting all and updating at once?
> 
> crypt_keeper_fields.each do |field|
>   plaintext = r[field]
> 
>   if plaintext.present?
>     r.send("#{field}=", enc.encrypt(plaintext))
>   end
> end
> 
> r.save!
> —
> Reply to this email directly or view it on GitHub.
>