Module: ActiveUUID::UUID
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/activeuuid/uuid.rb
Defined Under Namespace
Modules: ClassMethods, Instantiation
Instance Method Summary
collapse
Instance Method Details
#create_uuid ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/activeuuid/uuid.rb', line 144
def create_uuid
if _natural_key
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.timestamp_create
end
end
end
|
#generate_uuids_if_needed ⇒ Object
159
160
161
162
163
164
|
# File 'lib/activeuuid/uuid.rb', line 159
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
|