lib/unique_identifier.rb in unique_identifier-0.0.2 vs lib/unique_identifier.rb in unique_identifier-0.0.3

- old
+ new

@@ -4,25 +4,27 @@ module UniqueIdentifier module ClassMethods mattr_accessor :field, :block, :klass - + def unique_id(field, block) @klass = self.name.constantize @klass.const_set('BLOCK', block) @klass.const_set('FIELD', field) @klass.set_callback(:create, :before, :generate_unique_id) end - + end module InstanceMethods def generate_unique_id return if self.send(self.class::FIELD) identifier = loop do random = self.class::BLOCK.call - break random unless self.class.exists?(self.class::FIELD => random) + unless self.class.base_class.exists?(self.class::FIELD => random) + break random + end end self.send "#{self.class::FIELD}=", identifier end end