lib/lockbox/utils.rb in lockbox-0.3.1 vs lib/lockbox/utils.rb in lockbox-0.3.2

- old
+ new

@@ -1,18 +1,27 @@ module Lockbox class Utils def self.build_box(context, options, table, attribute) - options = options.except(:attribute, :encrypted_attribute, :migrating, :attached, :type, :encode) + options = options.except(:attribute, :encrypted_attribute, :migrating, :attached, :type) options.each do |k, v| if v.is_a?(Proc) options[k] = context.instance_exec(&v) if v.respond_to?(:call) elsif v.is_a?(Symbol) options[k] = context.send(v) end end unless options[:key] || options[:encryption_key] || options[:decryption_key] options[:key] = Lockbox.attribute_key(table: table, attribute: attribute, master_key: options.delete(:master_key)) + end + + if options[:previous_versions].is_a?(Array) + options[:previous_versions] = options[:previous_versions].dup + options[:previous_versions].each_with_index do |version, i| + if !(version[:key] || version[:encryption_key] || version[:decryption_key]) && version[:master_key] + options[:previous_versions][i] = version.merge(key: Lockbox.attribute_key(table: table, attribute: attribute, master_key: version.delete(:master_key))) + end + end end Lockbox.new(**options) end