Module: Uniquefy::ClassMethods
- Defined in:
- lib/uniquefy.rb
Instance Method Summary collapse
Instance Method Details
#uniquefy(*args, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/uniquefy.rb', line 20 def uniquefy(*args, &block) = { :length => 8, :chars => ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a } .merge!(args.pop) if args.last.kind_of? Hash args.each do |name| before_create do |record| if block record.ensure_unique(name, &block) else record.ensure_unique(name) do Array.new([:length]) { [:chars].to_a[rand([:chars].to_a.size)] }.join end end end end end |