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_uuidObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/activeuuid/uuid.rb', line 119

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(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_neededObject



134
135
136
137
138
139
# File 'lib/activeuuid/uuid.rb', line 134

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