lib/blind_index/model.rb in blind_index-0.1.0 vs lib/blind_index/model.rb in blind_index-0.1.1

- old
+ new

@@ -1,8 +1,8 @@ module BlindIndex module Model - def blind_index(name, key: nil, iterations: nil, attribute: nil, expression: nil, bidx_attribute: nil) + def blind_index(name, key: nil, iterations: nil, attribute: nil, expression: nil, bidx_attribute: nil, callback: true) iterations ||= 10000 attribute ||= name bidx_attribute ||= :"encrypted_#{name}_bidx" name = name.to_sym @@ -24,12 +24,15 @@ attribute: attribute, expression: expression, bidx_attribute: bidx_attribute } - before_validation method_name, if: -> { changes.key?(attribute.to_s) } define_method method_name do self.send("#{bidx_attribute}=", BlindIndex.generate_bidx(send(attribute), self.class.blind_indexes[name])) + end + + if callback + before_validation method_name, if: -> { changes.key?(attribute.to_s) } end end end end end