Module: Uuidable::ActiveRecord::ClassMethods
- Defined in:
- lib/uuidable/active_record.rb
Overview
ClassMethods
Instance Method Summary collapse
Instance Method Details
#find(*args) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/uuidable/active_record.rb', line 10 def find(*args) if args.first && args.first.is_a?(String) && args.first.match(UUIDTools::UUID_REGEXP) find_by_uuid!(*args) else super end end |
#uuidable ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/uuidable/active_record.rb', line 18 def uuidable after_initialize { self.uuid = Uuidable.generate_uuid if uuid.blank? } validates :uuid, presence: true, uniqueness: true define_method :to_param do uuid end define_method :uuid= do |val| raise UuidChangeError, 'Uuid changing is bad idea!' unless new_record? || uuid.blank? || uuid == val super(val) end end |