Module: ActiveID::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/active_id/model.rb
Overview
Include this module into all models which are meant to store UUIDs.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#create_uuid ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/active_id/model.rb', line 32 def create_uuid if _natural_key # TODO if all the attributes return nil you might want to warn about this chained = _natural_key.map { |attribute| send(attribute) }.join("-") UUIDTools::UUID.sha1_create(_uuid_namespace || UUIDTools::UUID_OID_NAMESPACE, chained) else case _uuid_generator when :random UUIDTools::UUID.random_create when :time UUIDTools::UUID. end end end |
#generate_uuids_if_needed ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/active_id/model.rb', line 47 def generate_uuids_if_needed primary_key = self.class.primary_key primary_key_attribute_type = self.class.type_for_attribute(primary_key) if ::ActiveID::Type::Base === primary_key_attribute_type send("#{primary_key}=", create_uuid) unless send("#{primary_key}?") end end |