lib/blind_index/model.rb in blind_index-0.3.0 vs lib/blind_index/model.rb in blind_index-0.3.2

- old
+ new

@@ -1,35 +1,46 @@ 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) + 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) iterations ||= 10000 attribute ||= name bidx_attribute ||= :"encrypted_#{name}_bidx" name = name.to_sym attribute = attribute.to_sym method_name = :"compute_#{name}_bidx" class_eval do - class << self - def blind_indexes - @blind_indexes ||= {} - end unless method_defined?(:blind_indexes) + @blind_indexes ||= {} + + unless respond_to?(:blind_indexes) + def self.blind_indexes + parent_indexes = + if superclass.respond_to?(:blind_indexes) + superclass.blind_indexes + else + {} + end + + parent_indexes.merge(@blind_indexes || {}) + end end raise BlindIndex::Error, "Duplicate blind index: #{name}" if blind_indexes[name] - blind_indexes[name] = { + @blind_indexes[name] = { key: key, iterations: iterations, attribute: attribute, expression: expression, bidx_attribute: bidx_attribute, algorithm: algorithm, insecure_key: insecure_key, - encode: encode + encode: encode, + cost: cost }.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]) end define_method method_name do