Module: GenToken::ActiveRecordInstanceMethods

Defined in:
lib/gen_token.rb

Instance Method Summary collapse

Instance Method Details

#generate_tokensObject



16
17
18
19
20
21
22
23
24
# File 'lib/gen_token.rb', line 16

def generate_tokens
  self.class.read_inheritable_attribute(:token_fields).each do |token|
    name, type, length = token[:name], token[:type], token[:length]
    self[token[:name]] = ActiveSupport::SecureRandom.send(:"#{token[:type]}", token[:length])
    while !self.class.send(:"find_by_#{token[:name]}", self[token[:name]]).nil?
      self[token[:name]] = ActiveSupport::SecureRandom.send(:"#{token[:type]}", token[:length])
    end
  end
end