lib/blind_index.rb in blind_index-0.1.1 vs lib/blind_index.rb in blind_index-0.2.0
- old
+ new
@@ -14,22 +14,29 @@
raise BlindIndex::Error, "Missing key for blind index" unless key
# apply expression
value = expression.call(value) if expression
- # generate hash
- digest = OpenSSL::Digest::SHA256.new
- value = OpenSSL::PKCS5.pbkdf2_hmac(value.to_s, key, iterations, digest.digest_length, digest)
+ unless value.nil?
+ # generate hash
+ digest = OpenSSL::Digest::SHA256.new
+ value = OpenSSL::PKCS5.pbkdf2_hmac(value.to_s, key, iterations, digest.digest_length, digest)
- # encode
- [value].pack("m")
+ # encode
+ [value].pack("m")
+ end
end
end
ActiveSupport.on_load(:active_record) do
require "blind_index/extensions"
extend BlindIndex::Model
- ActiveRecord::TableMetadata.prepend(BlindIndex::Extensions::TableMetadata)
+
+ if defined?(ActiveRecord::TableMetadata)
+ ActiveRecord::TableMetadata.prepend(BlindIndex::Extensions::TableMetadata)
+ else
+ ActiveRecord::PredicateBuilder.singleton_class.prepend(BlindIndex::Extensions::PredicateBuilder)
+ end
unless ActiveRecord::VERSION::STRING.start_with?("5.1.")
ActiveRecord::Validations::UniquenessValidator.prepend(BlindIndex::Extensions::UniquenessValidator)
end
end