fertile_forest 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aeedf9262be5d3ed03c75569600ec77362ac50ab
4
- data.tar.gz: c03cb41aad81c3a4753bb115018b972a3aa46b09
3
+ metadata.gz: 7f605105d5db7a7769a308ee81c2f2643840f9ef
4
+ data.tar.gz: 915263e1161b69364dc04b0e31ff3399d5dab13a
5
5
  SHA512:
6
- metadata.gz: a1162dc128d8cf90254d7bd4a5f296e24f040d75a1f074cf7def68f95ba2743002e7ec891eaaee9249364052e6a60488b1068c5735854c37df78647c93c6ae4d
7
- data.tar.gz: 1f3309e6c442cf50dcfcc43a50e0997567c4578d11e81794198fa4264bbf0af2dd912939e98a7d519b056d8cd4b752178c539c6085ef57b43dedcd4e2f505a07
6
+ metadata.gz: f8eb476e94442c5525097baac81878594cfe7a280bfe99e12b656d816db113641d907421880600e96038dc6888ddc91a8b4fe4bc82857336a21f6f58fbec4255
7
+ data.tar.gz: 0f7fa37321ebc48a02837f450fa0749412cadfa4e50a1dd50fb72b5cd464b89929e3acaaae7d2ceceee8ed4442c2b3325818f82988fd159511abfda0fd88e0b2
@@ -188,6 +188,7 @@ module StewEucen
188
188
  self.class.grandchildren(self, columns)
189
189
  end
190
190
 
191
+ # @since 1.1.0
191
192
  def kinships(
192
193
  next_branch = KINSHIPS_AS_SIBLING,
193
194
  level_offset = KINSHIPS_SAME_LEVEL,
@@ -200,14 +201,17 @@ module StewEucen
200
201
  self.class.siblings(self, columns)
201
202
  end
202
203
 
204
+ # @since 1.1.0
203
205
  def cousins(columns = nil)
204
206
  self.class.cousins(self, columns)
205
207
  end
206
208
 
209
+ # @since 1.1.0
207
210
  def niblings(columns = nil)
208
211
  self.class.niblings(self, columns)
209
212
  end
210
213
 
214
+ # @since 1.1.0
211
215
  def piblings(columns = nil)
212
216
  self.class.piblings(self, columns)
213
217
  end
@@ -146,6 +146,67 @@ module StewEucen
146
146
  trunk_query.first
147
147
  end
148
148
 
149
+ #
150
+ # Find cenancestor nodes of given nodes from base node.
151
+ #
152
+ # @param objects [Array] Array of base nodes|ids to find.
153
+ # @param columns [Array] Columns for SELECT clause.
154
+ # @return [Entity] Grandparent node.
155
+ # @return [nil] No grandparent node.
156
+ # @since 1.2.0
157
+ def cenancestors(objects, columns = nil)
158
+ base_nodes = ff_resolve_nodes(objects)
159
+ return nil if base_nodes.blank?
160
+
161
+ entities = base_nodes.values
162
+
163
+ # if bases include null, can not find.
164
+ return nil if entities.include? nil
165
+
166
+ # check same grove.
167
+ if has_grove?
168
+ groves = entities.map {|n| n.ff_grove }
169
+ return nil if groves.min != groves.max
170
+ end
171
+
172
+ eldist_node = entities.first;
173
+ aim_grove = eldist_node.ff_grove # When no grove, nil
174
+
175
+ ffqq = arel_table[@_ff_queue]
176
+ ffdd = arel_table[@_ff_depth]
177
+ ffgg = arel_table[@_ff_grove]
178
+
179
+ queues = entities.map {|n| n.ff_queue }
180
+ head_queue = queues.min
181
+ tail_queue = queues.max
182
+
183
+ # create subquery to find top-depth in range of head-tail.
184
+ top_depth_subquery = ff_usual_projection(aim_grove)
185
+ .project(ffdd.minimum.as('top_depth'))
186
+ .where(ffqq.gteq(head_queue))
187
+ .where(ffqq.lteq(tail_queue))
188
+
189
+ # create subquery to find queues of ancestors.
190
+ aim_group = [ffdd]
191
+ aim_group.unshift(ffgg) if has_grove?
192
+
193
+ cenancestor_nodes_subquery = ff_usual_projection(aim_grove)
194
+ .project(ffqq.maximum.as('ancestor_queue'))
195
+ .where(ffqq.lt(head_queue))
196
+ .where(ffdd.lt(top_depth_subquery))
197
+ .group(aim_group)
198
+
199
+ # find nodes by ancestor queues
200
+ # must use IN(), because trunk() is for general purpose to find ancestors
201
+ # When one row, can use "=". When plural, can not use "=".
202
+ # Error: SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row
203
+ ff_required_columns_scope()
204
+ .ff_usual_conditions_scope(aim_grove)
205
+ .ff_usual_order_scope()
206
+ .where(ffqq.in(cenancestor_nodes_subquery))
207
+ .select(ff_all_optional_columns(columns))
208
+ end
209
+
149
210
  ######################################################################
150
211
 
151
212
  #
@@ -1,3 +1,3 @@
1
1
  module FertileForest
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fertile_forest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stew Eucen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-23 00:00:00.000000000 Z
11
+ date: 2015-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails