Module: Familia::Features::Relationships::ModelInstanceMethods

Defined in:
lib/familia/features/relationships.rb

Instance Method Summary collapse

Instance Method Details

#cleanup_all_relationships! ⇒ Object

Deprecated.

This method is poorly implemented and will be removed in v3.0. The participation collection removal logic was repetitive and difficult to debug. A cleaner implementation will be provided in a future version. See pull #115 for details.

Note:

Currently only removes from indexes, not participation collections

Comprehensive cleanup - remove from all relationships



214
215
216
217
218
219
220
# File 'lib/familia/features/relationships.rb', line 214

def cleanup_all_relationships!
  warn '[DEPRECATED] cleanup_all_relationships! will be removed in v3.0. See pull #115.'
  warn 'Not currently removing from participation collections. Only indexes will be cleaned.'

  # Remove from indexes
  remove_from_all_indexes if respond_to?(:remove_from_all_indexes)
end

#create_temp_key(base_name, ttl = 300) ⇒ Object

Instance method wrapper for create_temp_key



256
257
258
259
260
261
262
263
264
265
# File 'lib/familia/features/relationships.rb', line 256

def create_temp_key(base_name, ttl = 300)
  timestamp = Familia.now.to_i
  random_suffix = SecureRandom.hex(3)
  temp_key = Familia.join('temp', base_name, timestamp, random_suffix)

  # UnsortedSet immediate expiry to ensure cleanup even if operation fails
  dbclient.expire(temp_key, ttl)

  temp_key
end

#dbclient ⇒ Object

Direct Valkey/Redis access for instance methods



251
252
253
# File 'lib/familia/features/relationships.rb', line 251

def dbclient
  self.class.dbclient
end

#relationship_status ⇒ Hash

Get comprehensive relationship status for this object

Returns:

  • (Hash) —

    the identifier, participations and index memberships

Raises:



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/familia/features/relationships.rb', line 188

def relationship_status
  Familia.assert_replies_available!("#{self.class}#relationship_status")

  status = {
    identifier: identifier,
    current_participations: [],
    index_memberships: [],
  }

  # Get participation memberships
  status[:current_participations] = current_participations if respond_to?(:current_participations)

  # Get index memberships
  status[:index_memberships] = current_indexings if respond_to?(:current_indexings)

  status
end

#validate_relationships! ⇒ true

Validate that this object's relationships are consistent

Returns:

  • (true)

Raises:



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/familia/features/relationships.rb', line 229

def validate_relationships!
  Familia.assert_replies_available!("#{self.class}#validate_relationships!")

  errors = []

  # Validate identifier exists
  errors << 'Object identifier is nil' unless identifier

  # Validate participation memberships
  if respond_to?(:current_participations)
    current_participations.each do |membership|
      score = membership[:score]
      errors << "Invalid score in participation membership: #{membership}" if score && !score.is_a?(Numeric)
    end
  end

  raise RelationshipError, "Relationship validation failed for #{self}: #{errors.join('; ')}" if errors.any?

  true
end