Something went wrong. Try again.
Ruby implementation of Universal Entity IDs
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334# frozen_string_literal: true
require "active_record"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Schema.define do create_table :widgets, force: true do |t| t.string :name end
create_table :ueid_widgets, id: :string, force: true do |t| t.string :name endend
class ApplicationRecord < ActiveRecord::Base primary_abstract_class
before_create :assign_ueid
private
def assign_ueid self.id ||= UEID.generate(self.class) endend
class Widget < ActiveRecord::Baseend
class UeidWidget < ApplicationRecordend