genealogy 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDA5NTljZWI2Zjk0MjY1Yzk3YTBhZjc4OWIwZGNkM2FiYmJmMDkxOA==
4
+ NjI4ZDczNzRkODlkNzBhM2JmYTMwMjEzZmU4ODQ4NTA1MTRhMDRjOQ==
5
5
  data.tar.gz: !binary |-
6
- OWI1OTIzYzMwODUxNjRhYWZiMWY5MTEyYzI5NDAzMzQzNDNiNTQ0Mw==
6
+ MmQyMGQ1NGE3NGI4M2I1OGQyYTM1ZGUyN2E1OGMxYWZlZWMyMTQ5Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTY2YmY2OTIxZGNhNDRkOTUxOGM4MDc3N2I4NDJiNTk1MDJhYTZmZDc0M2Uz
10
- Nzg0OGQ3NTQ5MzdhMjMyMGIwMWNjOWIzYzJiMjMwMjk1OWUzMTBhYzI0NTRk
11
- OGQ3NTA0MjM1ZjZkMWFhOWI2MzNhZTFkNDk1ZDg5ZmE3Njc0NmY=
9
+ MGY5NWYwZGJkMDQ1YmM4YzU2ZTc0YmYyN2RmMTQ1ZGZmYmUwMDNiMDEzOGQ3
10
+ YjQ4YmU1YjU0MzdiMTliMTE5NjA5ODQ0MWZhYjY4ODA1ZGU3MjIzYTg3MjBk
11
+ NDc3NGIzNDkyMTZhNThiNTY5NWI4ZDhmM2E3NmFiZGU5ZjE2NGU=
12
12
  data.tar.gz: !binary |-
13
- NDc4OTM3NjVhYTdkYzBkODYwYWRjNDRmZmY2NTIyNzQ5MTNhMjI3YTA1Mjgz
14
- ODgxOGYwZDFkM2RlMDBjM2E1ZGQ3NTMxMjA0YmQ5ZTc1YjlhNTIzOGQ2MjY1
15
- MGVjOTE4NWQ2ZDVjN2RlYjMzZTliODZlMDlmZjFiNjU1M2RlNDg=
13
+ MmFhOWI1OTk5YjU3NWRhNGNiNjIwMGFmNDVkMzFkYzM0YzkxOGFkOWU3YTg5
14
+ MjQ0MzQ4NzhjZWU2MWRkNmI3ZDAyYWVmOTQ2YTEzMWEzMzVkNWNiZmE1MmRh
15
+ NWI2YWMxNDI2YjRiZGNmOWQ1OTBkNzYzN2UwN2Q1YTg0YzYzNDY=
@@ -9,7 +9,7 @@ module Genealogy
9
9
  define_method "add_#{parent}" do |relative|
10
10
  unless relative.nil?
11
11
  raise IncompatibleObjectException, "Both linked objects must be instances of class with genealogy enabled. Got classes #{relative.class} and #{self.genealogy_class}" unless relative.class.respond_to?(:genealogy_enabled)
12
- incompatible_parents = self.offspring | self.siblings.to_a | [self]
12
+ incompatible_parents = self.offspring | self.siblings | [self]
13
13
  raise IncompatibleRelationshipException, "#{relative} can't be #{parent} of #{self}" if incompatible_parents.include? relative
14
14
  raise WrongSexException, "Can't add a #{relative.sex} #{parent}" unless (parent == :father and relative.is_male?) or (parent == :mother and relative.is_female?)
15
15
  end
@@ -208,6 +208,8 @@ module Genealogy
208
208
  when sex_female_value
209
209
  child.add_father(options[:spouse]) if options[:spouse]
210
210
  child.add_mother(self)
211
+ else
212
+ raise WrongSexException, "Sex value not valid for #{self}"
211
213
  end
212
214
  end
213
215
  end
@@ -238,6 +240,8 @@ module Genealogy
238
240
  child.remove_father
239
241
  when sex_female_value
240
242
  child.remove_mother
243
+ else
244
+ raise WrongSexException, "Sex value not valid for #{self}"
241
245
  end
242
246
  end
243
247
  end
@@ -22,7 +22,7 @@ module Genealogy
22
22
  admitted_keys = [:sex_column, :sex_values, :father_column, :mother_column, :current_spouse_column, :current_spouse, :perform_validation]
23
23
  check_options(options, admitted_keys) do |key, value|
24
24
  if key == :sex_values
25
- raise WrongOptionException, ":sex_values option must be an array with two char: first for male sex symbol an last for female" unless value.is_a?(Array) and value.size == 2 and value.first.to_s.size == 1 and value.last.to_s.size == 1
25
+ raise WrongOptionException, ":sex_values option must be an array of length 2: first for male sex symbol an last for female" unless value.is_a?(Array) and value.size == 2
26
26
  end
27
27
  end
28
28
 
@@ -38,12 +38,12 @@ module Genealogy
38
38
  ## sex
39
39
  # class attributes
40
40
  class_attribute :sex_column, :sex_values, :sex_male_value, :sex_female_value
41
- self.sex_column = options[:sex_column] || :sex
42
- self.sex_values = (options[:sex_values] and options[:sex_values].to_a.map(&:to_s)) || ['M','F']
41
+ self.sex_column = options[:sex_column] || 'sex'
42
+ self.sex_values = options[:sex_values] || ['M','F']
43
43
  self.sex_male_value = self.sex_values.first
44
44
  self.sex_female_value = self.sex_values.last
45
45
  # instance attribute
46
- alias_attribute :sex, sex_column if self.sex_column != :sex
46
+ alias_attribute :sex, sex_column if self.sex_column != 'sex'
47
47
  # validation
48
48
  validates_presence_of sex_column
49
49
  validates_format_of sex_column, :with => /[#{sex_values.join}]/
@@ -61,7 +61,7 @@ module Genealogy
61
61
  if spouse = options[:spouse]
62
62
  raise WrongSexException, "Problems while looking for #{self}'s offspring made with spouse #{spouse} who should not be a #{spouse.sex}." if spouse.sex == sex
63
63
  end
64
- case sex
64
+ result = case sex
65
65
  when sex_male_value
66
66
  if options.keys.include?(:spouse)
67
67
  children_as_father.with(spouse.try(:id))
@@ -74,32 +74,13 @@ module Genealogy
74
74
  else
75
75
  children_as_mother
76
76
  end
77
+ else
78
+ raise WrongSexException, "Sex value not valid for #{self}"
77
79
  end
80
+ result.to_a
78
81
  end
79
82
  alias_method :children, :offspring
80
83
 
81
- # # offspring
82
- # def offspring(options = {})
83
- # if spouse = options[:spouse]
84
- # raise WrongSexException, "Problems while looking for #{self}'s offspring made with spouse #{spouse} who should not be a #{spouse.sex}." if spouse.sex == sex
85
- # end
86
- # case sex
87
- # when sex_male_value
88
- # if options.keys.include?(:spouse)
89
- # self.genealogy_class.where(father_id: id, mother_id: spouse.try(:id))
90
- # else
91
- # self.genealogy_class.where(father_id: id)
92
- # end
93
- # when sex_female_value
94
- # if options.keys.include?(:spouse)
95
- # self.genealogy_class.where(mother_id: id, father_id: spouse.try(:id))
96
- # else
97
- # self.genealogy_class.where(mother_id: id)
98
- # end
99
- # end
100
- # end
101
- # alias_method :children, :offspring
102
-
103
84
  def eligible_offspring
104
85
  self.genealogy_class.all - ancestors - offspring - siblings - [self]
105
86
  end
@@ -162,10 +143,10 @@ module Genealogy
162
143
  # ancestors
163
144
  def ancestors
164
145
  result = []
165
- remaining = parents.to_a.compact
146
+ remaining = parents.compact
166
147
  until remaining.empty?
167
148
  result << remaining.shift
168
- remaining += result.last.parents.to_a.compact
149
+ remaining += result.last.parents.compact
169
150
  end
170
151
  result.uniq
171
152
  end
@@ -252,15 +233,17 @@ module Genealogy
252
233
  when sex_female_value
253
234
  'female'
254
235
  else
255
- raise "undefined sex for #{self}"
236
+ raise WrongSexException, "Sex value not valid for #{self}"
256
237
  end
257
238
  end
258
239
 
259
240
  def is_female?
241
+ return female? if respond_to?(:female?)
260
242
  sex == sex_female_value
261
243
  end
262
244
 
263
245
  def is_male?
246
+ return male? if respond_to?(:male?)
264
247
  sex == sex_male_value
265
248
  end
266
249
 
@@ -1,3 +1,3 @@
1
1
  module Genealogy
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
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: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - masciugo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-23 00:00:00.000000000 Z
11
+ date: 2014-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: 2.99.0
83
83
  - !ruby/object:Gem::Dependency
84
- name: debugger
84
+ name: rspec-its
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ! '>='
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  requirements: []
146
146
  rubyforge_project: ! '[none]'
147
- rubygems_version: 2.3.0
147
+ rubygems_version: 2.1.10
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: Organise ActiveRecord models into a genealogical tree structure