mochigome 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mochigome_ver.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mochigome
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/query.rb CHANGED
@@ -37,24 +37,32 @@ module Mochigome
37
37
  # the access filter.
38
38
  focus_rel = self.class.relation_over_path(@layers_path)
39
39
 
40
- # TODO: Properly handle focus model that is not in layer types list
41
- key_path = @layers_path.take_while{|m| m != focus_model} + [focus_model]
42
- key_cols = key_path.map{|m|
43
- Arel::Table.new(m.table_name)[m.primary_key]
44
- }
45
-
46
40
  @aggregate_rels[focus_model] = {}
47
41
  data_models.each do |data_model|
48
42
  f2d_path = self.class.path_thru([focus_model, data_model]) #TODO: Handle nil here
49
43
  agg_path = nil
44
+ key_path = nil
50
45
  f2d_path.reverse.each do |link_model|
46
+ remainder = f2d_path.drop_while{|m| m != link_model}
51
47
  if @layers_path.include?(link_model)
52
- agg_path = f2d_path.drop_while{|m| m != link_model}
48
+ agg_path = remainder
49
+ key_path = @layers_path.take(@layers_path.index(focus_model)+1)
53
50
  break
51
+ else
52
+ # Route it from the closest layer model
53
+ @layers_path.each_with_index do |layer, i|
54
+ p = self.class.path_thru([layer, link_model]) + remainder.drop(1)
55
+ if agg_path.nil? || p.size <= agg_path.size
56
+ agg_path = p
57
+ key_path = @layers_path.take(i+1)
58
+ end
59
+ end
54
60
  end
55
61
  end
56
- # TODO: Properly handle focus model that is not in layer types list
57
- fail unless agg_path
62
+
63
+ key_cols = key_path.map{|m|
64
+ Arel::Table.new(m.table_name)[m.primary_key]
65
+ }
58
66
 
59
67
  agg_data_rel = self.class.relation_over_path(agg_path, focus_rel.dup)
60
68
  agg_data_rel = access_filtered_relation(agg_data_rel, @layers_path + agg_path)
@@ -212,8 +212,22 @@ describe Mochigome::Query do
212
212
  [Owner, Store, Product],
213
213
  :aggregate_sources => [[Product, Sale]]
214
214
  )
215
+ data_node = q.run
216
+
217
+ assert_equal "Jane's Store (North)", (data_node/1/0).name
218
+ assert_equal 11, (data_node/1/0)['Sales count']
215
219
 
216
- tbl = Arel::Table.new(Owner.table_name)
220
+ assert_equal "Jane Doe", (data_node/1).name
221
+ assert_equal 16, (data_node/1)['Sales count']
222
+
223
+ assert_equal 24, data_node['Sales count']
224
+ end
225
+
226
+ it "goes farther than layer list to include aggregate focus" do
227
+ q = Mochigome::Query.new(
228
+ [Owner, Store],
229
+ :aggregate_sources => [[Product, Sale]]
230
+ )
217
231
  data_node = q.run
218
232
 
219
233
  assert_equal "Jane's Store (North)", (data_node/1/0).name
@@ -225,6 +239,20 @@ describe Mochigome::Query do
225
239
  assert_equal 24, data_node['Sales count']
226
240
  end
227
241
 
242
+ it "does not collect aggregate data for layers below focus" do
243
+ q = Mochigome::Query.new(
244
+ [Owner, Store, Product, Category],
245
+ :aggregate_sources => [[Product, Sale]]
246
+ )
247
+ data_node = q.run
248
+
249
+ assert_equal "Product", (data_node/0/0/0)[:internal_type]
250
+ refute_nil (data_node/0/0/0)['Sales count']
251
+
252
+ assert_equal "Category", (data_node/0/0/0/0)[:internal_type]
253
+ assert_nil (data_node/0/0/0/0)['Sales count']
254
+ end
255
+
228
256
  it "can do conditional counts" do
229
257
  q = Mochigome::Query.new(
230
258
  [Category],
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mochigome
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Mike Simon
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-03 00:00:00 Z
18
+ date: 2012-03-09 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement