Module: Familia::Features::ExternalIdentifiers

Defined in:
lib/familia/features/external_identifiers.rb,
lib/familia/features/external_identifiers/external_identifier_field_type.rb

Overview

Familia::Features::ExternalIdentifiers

Defined Under Namespace

Modules: ClassMethods Classes: ExternalIdentifierFieldType

Instance Method Summary collapse

Instance Method Details

#destroy!Object



98
99
100
101
102
103
104
105
106
# File 'lib/familia/features/external_identifiers.rb', line 98

def destroy!
  # Clean up extid mapping when object is destroyed
  current_extid = instance_variable_get(:@extid)
  if current_extid
    self.class.extid_lookup.del(current_extid)
  end

  super if defined?(super)
end

#external_identifierObject



89
90
91
# File 'lib/familia/features/external_identifiers.rb', line 89

def external_identifier
  extid
end

#generate_external_identifierObject

Generate external identifier deterministically from objid



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/familia/features/external_identifiers.rb', line 70

def generate_external_identifier
  return nil unless respond_to?(:objid)

  current_objid = objid
  return nil if current_objid.nil? || current_objid.to_s.empty?

  # Convert objid to hex string for processing
  objid_hex = current_objid.delete('-') # Remove UUID hyphens if present

  # Generate deterministic external ID using SecureIdentifier
  external_part = Familia.shorten_to_external_id(objid_hex, base: 36)

  # Get prefix from feature options, default to "ext"
  options = self.class.feature_options(:external_identifiers)
  prefix = options[:prefix] || 'ext'

  "#{prefix}_#{external_part}"
end

#initObject



93
94
95
96
# File 'lib/familia/features/external_identifiers.rb', line 93

def init
  super if defined?(super)
  # External IDs are generated from objid, so no additional setup needed
end