Module: ActiveUUID::UUID
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/activeuuid/uuid.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#create_uuid ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/activeuuid/uuid.rb', line 143 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| self.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
158 159 160 161 162 163 |
# File 'lib/activeuuid/uuid.rb', line 158 def generate_uuids_if_needed primary_key = self.class.primary_key if self.class.columns_hash[primary_key].type == :uuid send("#{primary_key}=", create_uuid) unless send("#{primary_key}?") end end |