Module: Genealogy::CurrentSpouseMethods

Extended by:
ActiveSupport::Concern
Includes:
Constants
Defined in:
lib/genealogy/current_spouse_methods.rb

Overview

Module CurrentSpouseMethods provides methods to manage and query current spouse. It's included by the genealogy enabled AR model

Constant Summary

Constants included from Constants

Genealogy::Constants::AKA, Genealogy::Constants::DEFAULTS, Genealogy::Constants::LINEAGE2PARENT, Genealogy::Constants::OFF, Genealogy::Constants::OPPOSITESEX, Genealogy::Constants::PARENT2LINEAGE, Genealogy::Constants::PARENT2SEX, Genealogy::Constants::PEDIGREE, Genealogy::Constants::PEDIGREE_AND_DATES, Genealogy::Constants::SEX2PARENT

Instance Method Summary collapse

Instance Method Details

#add_current_spouse(spouse) ⇒ Boolean

add current spouse updating receiver and argument individuals foreign_key in a transaction

Parameters:

  • spouse (Object)

Returns:

  • (Boolean)

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/genealogy/current_spouse_methods.rb', line 11

def add_current_spouse(spouse)

  raise_unless_current_spouse_enabled
  check_incompatible_relationship(:current_spouse,spouse)

  if gclass.perform_validation_enabled
    self.current_spouse = spouse
    spouse.current_spouse = self
    transaction do
      spouse.save!
      save!
    end
  else
    transaction do
      self.update_attribute(:current_spouse,spouse)
      spouse.update_attribute(:current_spouse,self)
    end
  end

end

#ineligible_current_spousesArray

list of individual who cannot be current spouse

Returns:

  • (Array)

54
55
56
57
# File 'lib/genealogy/current_spouse_methods.rb', line 54

def ineligible_current_spouses
  raise_unless_current_spouse_enabled
  self.gclass.send(ssex.to_s.pluralize)
end

#remove_current_spouseBoolean

remove current spouse resetting receiver and argument individuals foreign_key in a transaction

Returns:

  • (Boolean)

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/genealogy/current_spouse_methods.rb', line 34

def remove_current_spouse
  raise_unless_current_spouse_enabled
  if gclass.perform_validation_enabled
    ex_current_spouse = current_spouse
    current_spouse.current_spouse = nil
    self.current_spouse = nil
    transaction do
      ex_current_spouse.save!
      save!
    end
  else
    transaction do
      current_spouse.update_attribute(:current_spouse,nil)
      self.update_attribute(:current_spouse,nil)
    end
  end
end