Module: Nifty::Utils::ActiveRecord::RandomString

Defined in:
lib/nifty/utils/active_record/random_string.rb

Defined Under Namespace

Modules: ClassMethods, ModelExtensions

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
# File 'lib/nifty/utils/active_record/random_string.rb', line 9

def self.included(base)
  base.extend ClassMethods
end

.random_string(type, opts = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/nifty/utils/active_record/random_string.rb', line 13

def self.random_string(type, opts = {})
  case type.to_sym
  when :uuid
    SecureRandom.uuid
  when :chars
    Nifty::Utils::RandomString.generate(opts)
  else
    SecureRandom.hex(opts[:length] || 24)
  end
end