Class: Familia::Features::Relationships::ParticipationRelationship

Inherits:
Data
  • Object
show all
Defined in:
lib/familia/features/relationships/participation_relationship.rb

Overview

Note:

target_class is resolved once at definition time for performance. Use _original_target for debugging/introspection to see what was passed.

ParticipationRelationship

Stores metadata about participation relationships defined at class level. Used to configure code generation and runtime behavior for participates_in and class_participates_in declarations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_original_targetObject (readonly)

Returns the value of attribute _original_target

Returns:

  • (Object)

    the current value of _original_target



18
19
20
# File 'lib/familia/features/relationships/participation_relationship.rb', line 18

def _original_target
  @_original_target
end

#collection_nameObject (readonly)

Returns the value of attribute collection_name

Returns:

  • (Object)

    the current value of collection_name



18
19
20
# File 'lib/familia/features/relationships/participation_relationship.rb', line 18

def collection_name
  @collection_name
end

#generate_participant_methodsObject (readonly)

Returns the value of attribute generate_participant_methods

Returns:

  • (Object)

    the current value of generate_participant_methods



18
19
20
# File 'lib/familia/features/relationships/participation_relationship.rb', line 18

def generate_participant_methods
  @generate_participant_methods
end

#method_prefixObject (readonly)

Returns the value of attribute method_prefix

Returns:

  • (Object)

    the current value of method_prefix



18
19
20
# File 'lib/familia/features/relationships/participation_relationship.rb', line 18

def method_prefix
  @method_prefix
end

#scoreObject (readonly)

Returns the value of attribute score

Returns:

  • (Object)

    the current value of score



18
19
20
# File 'lib/familia/features/relationships/participation_relationship.rb', line 18

def score
  @score
end

#stagedObject (readonly)

Returns the value of attribute staged

Returns:

  • (Object)

    the current value of staged



18
19
20
# File 'lib/familia/features/relationships/participation_relationship.rb', line 18

def staged
  @staged
end

#target_classObject (readonly)

Returns the value of attribute target_class

Returns:

  • (Object)

    the current value of target_class



18
19
20
# File 'lib/familia/features/relationships/participation_relationship.rb', line 18

def target_class
  @target_class
end

#throughObject (readonly)

Returns the value of attribute through

Returns:

  • (Object)

    the current value of through



18
19
20
# File 'lib/familia/features/relationships/participation_relationship.rb', line 18

def through
  @through
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



18
19
20
# File 'lib/familia/features/relationships/participation_relationship.rb', line 18

def type
  @type
end

Instance Method Details

#matches?(comparison_target, comparison_collection) ⇒ Boolean

Check if this relationship matches the given target and collection Handles namespace-agnostic class comparison

Parameters:

  • comparison_target (Class, String, Symbol)

    target to compare against

  • comparison_collection (Symbol, String)

    collection name to compare

Returns:

  • (Boolean)

    true if both target and collection match



51
52
53
54
55
56
57
58
# File 'lib/familia/features/relationships/participation_relationship.rb', line 51

def matches?(comparison_target, comparison_collection)
  # Normalize comparison target to base class name
  comparison_target = comparison_target.name if comparison_target.is_a?(Class)
  comparison_target_base = comparison_target.to_s.split('::').last

  target_class_base == comparison_target_base &&
    collection_name == comparison_collection.to_sym
end

#resolved_through_classClass?

Resolve the through class to an actual Class object

Returns:

  • (Class, nil)

    The resolved through class or nil



70
71
72
73
74
# File 'lib/familia/features/relationships/participation_relationship.rb', line 70

def resolved_through_class
  return nil unless through

  through.is_a?(Class) ? through : Familia.resolve_class(through)
end

#staged?Boolean

Check if this relationship uses staged activation

Returns:

  • (Boolean)

    true if staging set is configured



79
80
81
# File 'lib/familia/features/relationships/participation_relationship.rb', line 79

def staged?
  !staged.nil?
end

#staging_collection_nameSymbol?

Get the staging collection name

Returns:

  • (Symbol, nil)

    The staging collection name or nil



86
87
88
# File 'lib/familia/features/relationships/participation_relationship.rb', line 86

def staging_collection_name
  staged
end

#target_class_baseString

Get the base class name without namespace Handles anonymous class wrappers like "#Class:0x123::SymbolResolutionCustomer"

Returns:

  • (String)

    base class name (e.g., "Customer")



41
42
43
# File 'lib/familia/features/relationships/participation_relationship.rb', line 41

def target_class_base
  target_class.name.split('::').last
end

#through_model?Boolean

Check if this relationship uses a through model

Returns:

  • (Boolean)

    true if through model is configured



63
64
65
# File 'lib/familia/features/relationships/participation_relationship.rb', line 63

def through_model?
  !through.nil?
end

#unique_keyString

Get a unique key for this participation relationship Useful for comparisons and hash keys

Returns:

  • (String)

    unique identifier in format "TargetClass:collection_name"



33
34
35
# File 'lib/familia/features/relationships/participation_relationship.rb', line 33

def unique_key
  Familia.join(target_class_base, collection_name)
end