Module: ActsAsRandomId::ModelAdditions
- Defined in:
- lib/acts_as_random_id/model_additions.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#ensure_unique_id(options) ⇒ Integer, String
Handles a generate unique ID.
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/acts_as_random_id/model_additions.rb', line 3 def self.included(base) base.send :extend, ClassMethods # Handles a generate unique ID # @param [Hash] options. The default format is "!{:field => :id}". # @return [Integer, String] the value of unique ID. def ensure_unique_id() begin self.send "#{[:field]}=", yield end while self.class.exists?([:field] => self.send([:field])) end end |
Instance Method Details
#ensure_unique_id(options) ⇒ Integer, String
Handles a generate unique ID
9 10 11 12 13 |
# File 'lib/acts_as_random_id/model_additions.rb', line 9 def ensure_unique_id() begin self.send "#{[:field]}=", yield end while self.class.exists?([:field] => self.send([:field])) end |