lib/blind_index/model.rb in blind_index-0.3.3 vs lib/blind_index/model.rb in blind_index-0.3.4

- 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, callback: true, algorithm: nil, insecure_key: nil, encode: nil, cost: nil) + def blind_index(name, key: nil, iterations: nil, attribute: nil, expression: nil, bidx_attribute: nil, callback: true, algorithm: nil, insecure_key: nil, encode: nil, cost: nil, size: nil) iterations ||= 10000 attribute ||= name bidx_attribute ||= :"encrypted_#{name}_bidx" name = name.to_sym @@ -34,11 +34,12 @@ expression: expression, bidx_attribute: bidx_attribute, algorithm: algorithm, insecure_key: insecure_key, encode: encode, - cost: cost + cost: cost, + size: size }.reject { |_, v| v.nil? } # should have been named generate_#{name}_bidx define_singleton_method method_name do |value| BlindIndex.generate_bidx(value, blind_indexes[name]) @@ -47,15 +48,10 @@ define_method method_name do self.send("#{bidx_attribute}=", self.class.send(method_name, send(attribute))) end if callback - if ActiveRecord::VERSION::STRING >= "5.1" - before_validation method_name, if: :"will_save_change_to_#{attribute}?" - else - before_validation method_name, if: -> { changes.key?(attribute.to_s) } - end - + before_validation method_name, if: -> { changes.key?(attribute.to_s) } end # use include so user can override include InstanceMethods if blind_indexes.size == 1 end