lib/tokenize.rb in jt-rails-tokenizable-1.0.7 vs lib/tokenize.rb in jt-rails-tokenizable-1.0.8
- old
+ new
@@ -6,30 +6,30 @@
end
module ClassMethods
def tokenize(field, options = {})
- @@jt_rails_token_fields ||= {}
+ jt_rails_token_fields[field.to_sym] = options
- @@jt_rails_token_fields[field.to_sym] = options
-
if options.fetch(:valiations, true)
validates field, presence: true, uniqueness: true
end
end
+ def jt_rails_token_fields
+ @@jt_rails_token_fields ||= {}
+ end
+
end
def jt_rails_generate_tokens
- @@jt_rails_token_fields ||= {}
-
- for field in @@jt_rails_token_fields.keys
+ for field in self.class.jt_rails_token_fields.keys
generate_new_token(field)
end
end
def generate_new_token(field)
- size = @@jt_rails_token_fields[field.to_sym].fetch(:size, 32)
+ size = self.class.jt_rails_token_fields[field.to_sym].fetch(:size, 32)
self[field.to_sym] = loop do
random_token = SecureRandom.hex(size)
break random_token unless self.class.exists?(field => random_token)
end