class Trocla::Util

Public Class Methods

random_str(length=12, charset='default') click to toggle source
# File lib/trocla/util.rb, line 5
def random_str(length=12, charset='default')
  _charsets = charsets[charset] || charsets['default']
  (1..length).collect{|a| _charsets[SecureRandom.random_number(_charsets.size)] }.join.to_s
end
salt(length=8) click to toggle source
# File lib/trocla/util.rb, line 10
def salt(length=8)
  alphanumeric_size = alphanumeric.size
  (1..length).collect{|a| alphanumeric[SecureRandom.random_number(alphanumeric_size)] }.join.to_s
end

Private Class Methods

alphanumeric() click to toggle source
# File lib/trocla/util.rb, line 36
def alphanumeric
  @alphanumeric ||= ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
end
chars() click to toggle source
# File lib/trocla/util.rb, line 27
def chars
  @chars ||= shellsafe + special_chars
end
charsets() click to toggle source
# File lib/trocla/util.rb, line 17
def charsets
  @charsets ||= {
    'default'       => chars,
    'alphanumeric'  => alphanumeric,
    'shellsafe'     => shellsafe,
    'windowssafe'   => windowssafe,
    'numeric'       => numeric,
  }
end
numeric() click to toggle source
# File lib/trocla/util.rb, line 39
def numeric
  @numeric ||= ('0'..'9').to_a
end
shellsafe() click to toggle source
# File lib/trocla/util.rb, line 30
def shellsafe
  @shellsafe ||= alphanumeric + shellsafe_chars
end
shellsafe_chars() click to toggle source
# File lib/trocla/util.rb, line 45
def shellsafe_chars
  @shellsafe_chars ||= "+%/@=?_.,:".split(//)
end
special_chars() click to toggle source
# File lib/trocla/util.rb, line 42
def special_chars
  @special_chars ||= "*()&![]{}-".split(//)
end
windowssafe() click to toggle source
# File lib/trocla/util.rb, line 33
def windowssafe
  @windowssafe ||= alphanumeric + windowssafe_chars
end
windowssafe_chars() click to toggle source
# File lib/trocla/util.rb, line 48
def windowssafe_chars
  @windowssafe_chars ||= "+%/@=?_.,".split(//)
end