Module: ActiveUUID::UUID::ClassMethods

Defined in:
lib/activeuuid/uuid.rb

Instance Method Summary collapse

Instance Method Details

#instantiate_with_uuid(record, record_models = nil) ⇒ Object



117
118
119
120
121
122
# File 'lib/activeuuid/uuid.rb', line 117

def instantiate_with_uuid(record, record_models = nil)
  uuid_columns.each do |uuid_column|
    record[uuid_column] = UUIDTools::UUID.serialize(record[uuid_column]).to_s if record[uuid_column]
  end
  instantiate_without_uuid(record)
end

#natural_key(*attributes) ⇒ Object



97
98
99
# File 'lib/activeuuid/uuid.rb', line 97

def natural_key(*attributes)
  self._natural_key = attributes
end

#uuid_columnsObject



124
125
126
# File 'lib/activeuuid/uuid.rb', line 124

def uuid_columns
  @uuid_columns ||= columns.select { |c| c.type == :uuid }.map(&:name)
end

#uuid_generator(generator_name) ⇒ Object



106
107
108
# File 'lib/activeuuid/uuid.rb', line 106

def uuid_generator(generator_name)
  self._uuid_generator = generator_name
end

#uuid_namespace(namespace) ⇒ Object



101
102
103
104
# File 'lib/activeuuid/uuid.rb', line 101

def uuid_namespace(namespace)
  namespace = UUIDTools::UUID.parse_string(namespace) unless namespace.is_a? UUIDTools::UUID
  self._uuid_namespace = namespace
end

#uuids(*attributes) ⇒ Object



110
111
112
113
114
115
# File 'lib/activeuuid/uuid.rb', line 110

def uuids(*attributes)
  ActiveSupport::Deprecation.warn <<-EOS
    ActiveUUID detects uuid columns independently.
    There is no more need to use uuid method.
  EOS
end