Class: DueCredit::Referrer
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- DueCredit::Referrer
- Defined in:
- app/models/due_credit/referrer.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#ensure_unique(&block) ⇒ Object
Ensures that the token will be unique when created.
Class Method Details
.generate_unique ⇒ Object
28 29 30 |
# File 'app/models/due_credit/referrer.rb', line 28 def self.generate_unique SecureRandom.hex(5) end |
Instance Method Details
#ensure_unique(&block) ⇒ Object
Ensures that the token will be unique when created
20 21 22 23 24 25 26 |
# File 'app/models/due_credit/referrer.rb', line 20 def ensure_unique(&block) begin self['token'] = (block ? block.call : self.class.generate_unique) end while self.class.exists?('token' => self['token']) self['token'] end |