diff options
| author | Szymon Szukalski <szymon@skas.io> | 2024-10-25 10:20:12 +1100 |
|---|---|---|
| committer | Szymon Szukalski <szymon@skas.io> | 2024-10-25 10:20:12 +1100 |
| commit | fd1a1064669587a778ca995555254d878904a5f8 (patch) | |
| tree | f54245151181b011613f760241bb3e9c045eac07 /lib/relationship_manager.rb | |
| parent | 05fda6c29f0fe4742b7ea6b237ea98f737b68b8b (diff) | |
Move link_spouses to FamilyFactory
Diffstat (limited to 'lib/relationship_manager.rb')
| -rw-r--r-- | lib/relationship_manager.rb | 31 |
1 files changed, 0 insertions, 31 deletions
diff --git a/lib/relationship_manager.rb b/lib/relationship_manager.rb deleted file mode 100644 index 30dfd94..0000000 --- a/lib/relationship_manager.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -require 'singleton' - -# RelationshipManager class to manage relationships between people. -# This class follows the Singleton pattern to ensure there is only one instance -# of the relationship manager throughout the application. -class RelationshipManager - include Singleton - - # Links two people as spouses. - # - # @param person1 [Person] The first person to link. - # @param person2 [Person] The second person to link. - # @raise [RuntimeError] if either person is already linked to someone else. - # @return [void] - def link_spouses(person1, person2) - # Check if either person is already linked to someone else - if person1.spouse != NilPerson.new && person1.spouse != person2 - raise "Cannot link #{person1.name} and #{person2.name}: #{person1.name} is already linked to #{person1.spouse.name}." - end - - if person2.spouse != NilPerson.new && person2.spouse != person1 - raise "Cannot link #{person1.name} and #{person2.name}: #{person2.name} is already linked to #{person2.spouse.name}." - end - - # Link the spouses - person1.spouse = person2 - person2.spouse = person1 unless person2.is_a?(NilPerson) - end -end |
