Module: Familia::Features::ObjectIdentifier::ModelClassMethods
- Defined in:
- lib/familia/features/object_identifier.rb
Instance Method Summary collapse
-
#find_by_objid(objid) ⇒ Object?
Find an object by its object identifier.
-
#generate_object_identifier ⇒ String
Generate a new object identifier using the configured strategy.
Instance Method Details
#find_by_objid(objid) ⇒ Object?
Find an object by its object identifier
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/familia/features/object_identifier.rb', line 263 def find_by_objid(objid) return nil if objid.to_s.empty? if Familia.debug? reference = caller(1..1).first Familia.trace :FIND_BY_OBJID, nil, objid, reference end # Look up the primary ID from the external ID mapping primary_id = objid_lookup[objid] # If there is no mapping for this instance's objid, perhaps # the object dbkey is already using the objid. primary_id = objid if primary_id.nil? find_by_id(primary_id) rescue Familia::NotFound # If the object was deleted but mapping wasn't cleaned up # we could autoclean here, as long as we log it. # objid_lookup.remove_field(objid) nil end |
#generate_object_identifier ⇒ String
Generate a new object identifier using the configured strategy
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/familia/features/object_identifier.rb', line 235 def generate_object_identifier = (:object_identifier) generator = [:generator] || DEFAULT_GENERATOR case generator when :uuid_v7 SecureRandom.uuid_v7 when :uuid_v4 SecureRandom.uuid_v4 when :hex Familia.generate_id(16) when Proc generator.call else unless generator.respond_to?(:call) raise Familia::Problem, "Invalid object identifier generator: #{generator.inspect}" end generator.call end end |