genealogy 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/genealogy/genealogy.rb +7 -28
- data/lib/genealogy/ineligible_methods.rb +2 -2
- data/lib/genealogy/query_methods.rb +11 -12
- data/lib/genealogy/util_methods.rb +24 -1
- data/lib/genealogy/version.rb +1 -1
- metadata +31 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f8bcecb22a6962bc6220672801e068737865d783
|
|
4
|
+
data.tar.gz: 015a4ab711a4010f541370fcd90c57bd491210a5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f32db53259941b8f7583249892d27edf49144e741b03765f21d0b2effd521098d94b4377cad02433e39e2de6643dedbefb048f36c30e9ed4302b7cc6202d2721
|
|
7
|
+
data.tar.gz: 6b4727c0a01fa9d61a63901bc40cbcf55b2134150636dc8570b16f83b9cf9eae5bda53e643442c5c934c81ecb603c2f91b8b9ee46dbdab1fe8c22b50ccecb4f0
|
data/lib/genealogy/genealogy.rb
CHANGED
|
@@ -21,7 +21,13 @@ module Genealogy
|
|
|
21
21
|
# @return [void]
|
|
22
22
|
def has_parents options = {}
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
include Genealogy::UtilMethods
|
|
25
|
+
include Genealogy::QueryMethods
|
|
26
|
+
include Genealogy::IneligibleMethods
|
|
27
|
+
include Genealogy::AlterMethods
|
|
28
|
+
include Genealogy::CurrentSpouseMethods
|
|
29
|
+
|
|
30
|
+
check_has_parents_options(options)
|
|
25
31
|
|
|
26
32
|
# keep track of the original extend class to prevent wrong scopes in query method in case of STI
|
|
27
33
|
class_attribute :gclass, instance_writer: false
|
|
@@ -85,33 +91,6 @@ module Genealogy
|
|
|
85
91
|
has_many :children_as_father, class_name: self, foreign_key: self.father_id_column, dependent: :nullify
|
|
86
92
|
has_many :children_as_mother, class_name: self, foreign_key: self.mother_id_column, dependent: :nullify
|
|
87
93
|
|
|
88
|
-
include Genealogy::UtilMethods
|
|
89
|
-
include Genealogy::QueryMethods
|
|
90
|
-
include Genealogy::IneligibleMethods
|
|
91
|
-
include Genealogy::AlterMethods
|
|
92
|
-
include Genealogy::CurrentSpouseMethods
|
|
93
|
-
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
private
|
|
97
|
-
|
|
98
|
-
def check_options(options)
|
|
99
|
-
|
|
100
|
-
raise ArgumentError, "Hash expected, #{options.class} given." unless options.is_a? Hash
|
|
101
|
-
|
|
102
|
-
# column names
|
|
103
|
-
options[:column_names] ||= {}
|
|
104
|
-
raise ArgumentError, "Hash expected for :column_names option, #{options[:column_names].class} given." unless options[:column_names].is_a? Hash
|
|
105
|
-
|
|
106
|
-
# sex
|
|
107
|
-
if array = options[:sex_values]
|
|
108
|
-
raise ArgumentError, ":sex_values option must be an array of length 2: [:male_value, :female_value]" unless array.is_a?(Array) and array.size == 2
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
# booleans
|
|
112
|
-
options.slice(:perform_validation, :current_spouse).each do |k,v|
|
|
113
|
-
raise ArgumentError, "Boolean expected for #{k} option, #{v.class} given." unless !!v == v
|
|
114
|
-
end
|
|
115
94
|
end
|
|
116
95
|
|
|
117
96
|
end
|
|
@@ -87,8 +87,8 @@ module Genealogy
|
|
|
87
87
|
ineligibles = []
|
|
88
88
|
if gclass.ineligibility_level >= PEDIGREE
|
|
89
89
|
ineligibles |= ancestors | descendants | siblings | [self]
|
|
90
|
-
ineligibles |= (father ? gclass.all_with(:father).where
|
|
91
|
-
ineligibles |= (mother ? gclass.all_with(:mother).where
|
|
90
|
+
ineligibles |= (father ? gclass.all_with(:father).where("father_id != ?", father) : [])
|
|
91
|
+
ineligibles |= (mother ? gclass.all_with(:mother).where("mother_id != ?", mother) : [])
|
|
92
92
|
end
|
|
93
93
|
if gclass.ineligibility_level >= PEDIGREE_AND_DATES
|
|
94
94
|
# if a parent is present ineligible siblings are parent's ineligible children, otherwise try to estimate parent birth range.
|
|
@@ -28,12 +28,12 @@ module Genealogy
|
|
|
28
28
|
|
|
29
29
|
# @return [2-elements Array] paternal_grandfather and paternal_grandmother
|
|
30
30
|
def paternal_grandparents
|
|
31
|
-
father && father.parents
|
|
31
|
+
(father && father.parents) || [nil,nil]
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
# @return [2-elements Array] maternal_grandfather and maternal_grandmother
|
|
35
35
|
def maternal_grandparents
|
|
36
|
-
mother && mother.parents
|
|
36
|
+
(mother && mother.parents) || [nil,nil]
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
# @return [4-elements Array] paternal_grandfather, paternal_grandmother, maternal_grandfather, maternal_grandmother
|
|
@@ -51,10 +51,10 @@ module Genealogy
|
|
|
51
51
|
# @return [ActiveRecord::Relation] children
|
|
52
52
|
def children(options = {})
|
|
53
53
|
raise SexError, "Sex value not valid for #{self}. It's needed to look for children" unless gclass.sex_values.include? sex
|
|
54
|
-
result = gclass.where(SEX2PARENT[ssex] => self)
|
|
54
|
+
result = gclass.where("#{SEX2PARENT[ssex]}_id" => self)
|
|
55
55
|
if options.keys.include? :spouse
|
|
56
56
|
check_indiv(spouse = options[:spouse],opposite_ssex)
|
|
57
|
-
result = result.where(SEX2PARENT[opposite_ssex] => spouse ) if spouse
|
|
57
|
+
result = result.where("#{SEX2PARENT[opposite_ssex]}_id" => spouse ) if spouse
|
|
58
58
|
end
|
|
59
59
|
result
|
|
60
60
|
end
|
|
@@ -73,8 +73,7 @@ module Genealogy
|
|
|
73
73
|
# @return [ActiveRecord::Relation] list of fullsiblings and/or halfsiblings
|
|
74
74
|
def siblings(options = {})
|
|
75
75
|
spouse = options[:spouse]
|
|
76
|
-
|
|
77
|
-
result = gclass.where.not(id: id)
|
|
76
|
+
result = gclass.where("id != ?",id)
|
|
78
77
|
case options[:half]
|
|
79
78
|
when nil # only full siblings
|
|
80
79
|
result.all_with(:parents).where(father_id: father, mother_id: mother)
|
|
@@ -84,7 +83,7 @@ module Genealogy
|
|
|
84
83
|
check_indiv(spouse, :female)
|
|
85
84
|
result.where(mother_id: spouse)
|
|
86
85
|
elsif mother
|
|
87
|
-
result.where("
|
|
86
|
+
result.where("mother_id != ? or mother_id is ?", mother_id, nil)
|
|
88
87
|
else
|
|
89
88
|
result
|
|
90
89
|
end
|
|
@@ -94,7 +93,7 @@ module Genealogy
|
|
|
94
93
|
check_indiv(spouse, :male)
|
|
95
94
|
result.where(father_id: spouse)
|
|
96
95
|
elsif father
|
|
97
|
-
result.where("
|
|
96
|
+
result.where("father_id != ? or father_id is ?", father_id, nil)
|
|
98
97
|
else
|
|
99
98
|
result
|
|
100
99
|
end
|
|
@@ -102,7 +101,7 @@ module Genealogy
|
|
|
102
101
|
ids = siblings(half: :father).pluck(:id) | siblings(half: :mother).pluck(:id)
|
|
103
102
|
result.where(id: ids)
|
|
104
103
|
when :include # including half siblings
|
|
105
|
-
result.where("
|
|
104
|
+
result.where("father_id == ? or mother_id == ?", father_id, mother_id)
|
|
106
105
|
else
|
|
107
106
|
raise ArgumentError, "Admitted values for :half options are: :father, :mother, false, true or nil"
|
|
108
107
|
end
|
|
@@ -300,11 +299,11 @@ module Genealogy
|
|
|
300
299
|
def all_with(role)
|
|
301
300
|
case role
|
|
302
301
|
when :father
|
|
303
|
-
where
|
|
302
|
+
where('father_id is not ?',nil)
|
|
304
303
|
when :mother
|
|
305
|
-
where
|
|
304
|
+
where('mother_id is not ?',nil)
|
|
306
305
|
when :parents
|
|
307
|
-
where
|
|
306
|
+
where('father_id is not ? and mother_id is not ?',nil,nil)
|
|
308
307
|
end
|
|
309
308
|
end
|
|
310
309
|
|
|
@@ -172,9 +172,32 @@ module Genealogy
|
|
|
172
172
|
end
|
|
173
173
|
|
|
174
174
|
def check_indiv(arg, arg_sex=nil)
|
|
175
|
-
raise ArgumentError, "Expected #{self.gclass} object. Got #{arg.class}" unless arg.
|
|
175
|
+
raise ArgumentError, "Expected #{self.gclass} object. Got #{arg.class}" unless arg.is_a? self.gclass
|
|
176
176
|
raise SexError, "Expected a #{arg_sex} as argument. Got a #{arg.ssex}" if arg_sex and arg.ssex != arg_sex
|
|
177
177
|
end
|
|
178
178
|
|
|
179
|
+
module ClassMethods
|
|
180
|
+
|
|
181
|
+
def check_has_parents_options(options)
|
|
182
|
+
|
|
183
|
+
raise ArgumentError, "Hash expected, #{options.class} given." unless options.is_a? Hash
|
|
184
|
+
|
|
185
|
+
# column names
|
|
186
|
+
options[:column_names] ||= {}
|
|
187
|
+
raise ArgumentError, "Hash expected for :column_names option, #{options[:column_names].class} given." unless options[:column_names].is_a? Hash
|
|
188
|
+
|
|
189
|
+
# sex
|
|
190
|
+
if array = options[:sex_values]
|
|
191
|
+
raise ArgumentError, ":sex_values option must be an array of length 2: [:male_value, :female_value]" unless array.is_a?(Array) and array.size == 2
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# booleans
|
|
195
|
+
options.slice(:perform_validation, :current_spouse).each do |k,v|
|
|
196
|
+
raise ArgumentError, "Boolean expected for #{k} option, #{v.class} given." unless !!v == v
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
end
|
|
201
|
+
|
|
179
202
|
end
|
|
180
203
|
end
|
data/lib/genealogy/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: genealogy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- masciugo
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-03-
|
|
11
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -94,6 +94,20 @@ dependencies:
|
|
|
94
94
|
- - ">="
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: simplecov
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
97
111
|
- !ruby/object:Gem::Dependency
|
|
98
112
|
name: database_cleaner
|
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -164,6 +178,20 @@ dependencies:
|
|
|
164
178
|
- - ">="
|
|
165
179
|
- !ruby/object:Gem::Version
|
|
166
180
|
version: '0'
|
|
181
|
+
- !ruby/object:Gem::Dependency
|
|
182
|
+
name: appraisal
|
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
|
184
|
+
requirements:
|
|
185
|
+
- - ">="
|
|
186
|
+
- !ruby/object:Gem::Version
|
|
187
|
+
version: '0'
|
|
188
|
+
type: :development
|
|
189
|
+
prerelease: false
|
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
191
|
+
requirements:
|
|
192
|
+
- - ">="
|
|
193
|
+
- !ruby/object:Gem::Version
|
|
194
|
+
version: '0'
|
|
167
195
|
- !ruby/object:Gem::Dependency
|
|
168
196
|
name: byebug
|
|
169
197
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -216,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
216
244
|
version: '0'
|
|
217
245
|
requirements: []
|
|
218
246
|
rubyforge_project: "[none]"
|
|
219
|
-
rubygems_version: 2.
|
|
247
|
+
rubygems_version: 2.4.5
|
|
220
248
|
signing_key:
|
|
221
249
|
specification_version: 4
|
|
222
250
|
summary: Make ActiveRecord model act as a pedigree
|