lib/tokenize.rb in jt-rails-tokenizable-1.1 vs lib/tokenize.rb in jt-rails-tokenizable-1.1.1
- old
+ new
@@ -33,12 +33,13 @@
end
end
def generate_new_token(field)
size = self.class.jt_rails_token_fields[field.to_sym].fetch(:size, 32)
+ only_digits = self.class.jt_rails_token_fields[field.to_sym].fetch(:only_digits, false)
self[field.to_sym] = loop do
- random_token = SecureRandom.hex(size)
+ random_token = only_digits ? SecureRandom.random_number(10**size) : SecureRandom.hex(size)
break random_token unless self.class.exists?(field => random_token)
end
end
end