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

- old
+ new

@@ -11,11 +11,11 @@ class_eval do class << self def blind_indexes @blind_indexes ||= {} - end unless respond_to?(:blind_indexes) + end unless method_defined?(:blind_indexes) end raise BlindIndex::Error, "Duplicate blind index: #{name}" if blind_indexes[name] blind_indexes[name] = { @@ -31,9 +31,22 @@ end if callback 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 + end + end + + module InstanceMethods + def read_attribute_for_validation(key) + if (bi = self.class.blind_indexes[key]) + send(bi[:attribute]) + else + super end end end end