Module: UniqueGenerator

Extended by:
ActiveSupport::Concern
Defined in:
lib/unique_generator.rb,
lib/unique_generator/version.rb

Defined Under Namespace

Modules: ClassMethods, UniqueChecks Classes: Railtie

Constant Summary collapse

CHOICES =
(Array('A'..'Z') + Array('a'..'z') + Array('0'..'9'))
VERSION =
"1.0.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.setup!Object



7
8
9
10
# File 'lib/unique_generator.rb', line 7

def self.setup!
  ActiveRecord::Base.send(:include, self) if defined?(ActiveRecord::Base)
  MongoMapper::Document.plugin(self)      if defined?(MongoMapper::Document)
end

Instance Method Details

#generate_unique_field!(name, size = 32) ⇒ Object

Generate unique field.



66
67
68
69
70
71
72
# File 'lib/unique_generator.rb', line 66

def generate_unique_field!(name, size = 32)
  return if send(name).present?
  self.class.generate_unique(size) do |token|
    send "#{name}=", token
    unique_field? name
  end
end