module ActsAsToken

Constants

VERSION

Public Instance Methods

column_name() click to toggle source
# File lib/acts_as_token.rb, line 38
def column_name
  self.class.instance_variable_get('@_column_name')
end
ensure_token_id!() click to toggle source
# File lib/acts_as_token.rb, line 23
def ensure_token_id!
  self.send("#{ column_name }=", generate_token_id)
end
generate_token_id() click to toggle source
# File lib/acts_as_token.rb, line 27
def generate_token_id
  loop do
    token = rand(10 ** length_of_token).to_s.rjust(length_of_token,'0')
    break token unless self.class.find_by("#{ column_name }" => token)
  end
end
length_of_token() click to toggle source
# File lib/acts_as_token.rb, line 34
def length_of_token
  self.class.instance_variable_get('@_length')
end