lib/lockbox/model.rb in lockbox-0.4.8 vs lib/lockbox/model.rb in lockbox-0.4.9
- old
+ new
@@ -30,16 +30,20 @@
# TODO raise ArgumentError in 0.5.0
warn "[lockbox] WARNING: No attributes specified" if attributes.empty?
raise ArgumentError, "Cannot use key_attribute with multiple attributes" if options[:key_attribute] && attributes.size > 1
+ original_options = options.dup
+
attributes.each do |name|
+ # per attribute options
+ # TODO use a different name
+ options = original_options.dup
+
# add default options
- encrypted_attribute = "#{name}_ciphertext"
+ encrypted_attribute = options.delete(:encrypted_attribute) || "#{name}_ciphertext"
- options = options.dup
-
# migrating
original_name = name.to_sym
name = "migrated_#{name}" if options[:migrating]
name = name.to_sym
@@ -80,10 +84,15 @@
def inspect
inspection =
serializable_hash.map do |k,v|
"#{k}: #{respond_to?(:attribute_for_inspect) ? attribute_for_inspect(k) : v.inspect}"
end
+
+ self.class.lockbox_attributes.map do |_, lockbox_attribute|
+ inspection << "#{lockbox_attribute[:attribute]}: [FILTERED]" if has_attribute?(lockbox_attribute[:encrypted_attribute])
+ end
+
"#<#{self.class} #{inspection.join(", ")}>"
end
if activerecord
# TODO wrap in module?
@@ -167,9 +176,10 @@
end
end
end
raise "Duplicate encrypted attribute: #{original_name}" if lockbox_attributes[original_name]
+ raise "Multiple encrypted attributes use the same column: #{encrypted_attribute}" if lockbox_attributes.any? { |_, v| v[:encrypted_attribute] == encrypted_attribute }
@lockbox_attributes[original_name] = options
if activerecord
# preference:
# 1. type option