Module: Uuidable::ActiveRecord::ClassMethods
- Includes:
- Finder
- Defined in:
- lib/uuidable/active_record.rb
Overview
ClassMethods
Instance Method Summary collapse
Methods included from Finder
Instance Method Details
#uuidable(as_param: true) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/uuidable/active_record.rb', line 22 def uuidable(as_param: true) after_initialize { self.uuid = Uuidable.generate_uuid if attributes.keys.include?('uuid') && uuid.blank? } validates :uuid, presence: true, uniqueness: true if as_param define_method :to_param do uuid end end define_method :uuid= do |val| raise UuidChangeError, 'Uuid changing is bad idea!' unless new_record? || uuid.blank? || uuid == val super(val) end end |