Module: Genealogy::ClassMethods
- Includes:
- Constants
- Defined in:
- lib/genealogy/genealogy.rb
Constant Summary
Constants included from Constants
Genealogy::Constants::AKA, Genealogy::Constants::DEFAULTS, Genealogy::Constants::LINEAGE2PARENT, Genealogy::Constants::OFF, Genealogy::Constants::OPPOSITELINEAGE, Genealogy::Constants::OPPOSITESEX, Genealogy::Constants::PARENT2LINEAGE, Genealogy::Constants::PARENT2SEX, Genealogy::Constants::PEDIGREE, Genealogy::Constants::PEDIGREE_AND_DATES, Genealogy::Constants::SEX2PARENT
Instance Method Summary collapse
-
#has_parents(options = {}) ⇒ void
gives to ActiveRecord model geneaogy capabilities.
Instance Method Details
#has_parents(options = {}) ⇒ void
This method returns an undefined value.
gives to ActiveRecord model geneaogy capabilities. Modules UtilMethods QueryMethods IneligibleMethods AlterMethods and SpouseMethods are included
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/genealogy/genealogy.rb', line 23 def has_parents = {} include Genealogy::UtilMethods include Genealogy::QueryMethods include Genealogy::ComplexQueryMethods include Genealogy::IneligibleMethods include Genealogy::AlterMethods include Genealogy::CurrentSpouseMethods () # keep track of the original extend class to prevent wrong scopes in query method in case of STI class_attribute :gclass, instance_writer: false self.gclass = self alias_attribute :id, self.primary_key.to_sym if self.primary_key != 'id' self.extend(Genealogy::ComplexQueryMethods::ClassMethods) class_attribute :ineligibility_level, instance_accessor: false self.ineligibility_level = case [:ineligibility] when :pedigree PEDIGREE when true PEDIGREE when :pedigree_and_dates PEDIGREE_AND_DATES when false OFF when nil PEDIGREE else raise ArgumentError, "ineligibility option must be one among :pedigree, :pedigree_and_dates or false" end ## limit_ages if ineligibility_level >= PEDIGREE_AND_DATES DEFAULTS[:limit_ages].each do |age,v| class_attribute age, instance_accessor: false self.send("#{age}=", [:limit_ages].try(:[],age) || v) end end [:current_spouse, :perform_validation].each do |opt| ca = "#{opt}_enabled" class_attribute ca, instance_accessor: false self.send "#{ca}=", .key?(opt) ? [opt] : DEFAULTS[opt] end # column names class attributes DEFAULTS[:column_names].merge([:column_names]).each do |k,v| class_attribute_name = "#{k}_column" class_attribute class_attribute_name, instance_accessor: false self.send("#{class_attribute_name}=", v) alias_attribute k, v unless k == v.to_sym end ## sex class_attribute :sex_values, :sex_male_value, :sex_female_value, instance_accessor: false self.sex_values = [:sex_values] || DEFAULTS[:sex_values] self.sex_male_value = self.sex_values.first self.sex_female_value = self.sex_values.last # validation validates_presence_of :sex validates_format_of :sex, with: /[#{sex_values.join}]/ tracked_relatives = [:father, :mother] tracked_relatives << :current_spouse if current_spouse_enabled = {class_name: self.name} [:optional] = true if Gem::Specification.find_by_name('activerecord').version >= Gem::Version.new("5") tracked_relatives.each do |k| belongs_to k, .merge(foreign_key: self.send("#{k}_id_column")) end has_many :children_as_father, class_name: self.name, foreign_key: self.father_id_column, dependent: :nullify has_many :children_as_mother, class_name: self.name, foreign_key: self.mother_id_column, dependent: :nullify end |