mochigome 0.2.4 → 0.2.5
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.
- data/lib/mochigome_ver.rb +1 -1
- data/lib/model_graph.rb +5 -1
- data/lib/query.rb +16 -0
- data/test/unit/query_test.rb +15 -0
- metadata +4 -4
data/lib/mochigome_ver.rb
CHANGED
data/lib/model_graph.rb
CHANGED
@@ -23,7 +23,11 @@ module Mochigome
|
|
23
23
|
# Take an expression and return a Set of all models it references
|
24
24
|
def expr_models(e)
|
25
25
|
r = Set.new
|
26
|
-
|
26
|
+
if e.is_a?(Array)
|
27
|
+
e.each{|sub_e| r += expr_models(sub_e)}
|
28
|
+
return r
|
29
|
+
end
|
30
|
+
[:expr, :left, :right, :expressions].each do |m|
|
27
31
|
r += expr_models(e.send(m)) if e.respond_to?(m)
|
28
32
|
end
|
29
33
|
if e.respond_to?(:relation)
|
data/lib/query.rb
CHANGED
@@ -37,6 +37,7 @@ module Mochigome
|
|
37
37
|
aggregate_sources = as_hash
|
38
38
|
end
|
39
39
|
|
40
|
+
agg_only_lines = []
|
40
41
|
aggregate_sources.each do |path, aggs|
|
41
42
|
models_path = path.drop(1) # Remove the :report symbol at the start
|
42
43
|
tgt_line = @lines.find do |line|
|
@@ -47,8 +48,23 @@ module Mochigome
|
|
47
48
|
end
|
48
49
|
aggs.each do |a|
|
49
50
|
tgt_line.add_aggregate_source(models_path.size, a)
|
51
|
+
if tgt_line.layer_path != models_path
|
52
|
+
# FIXME Copy&paste from add_aggregate_source
|
53
|
+
if a.is_a?(Array) then
|
54
|
+
focus_model = a.select{|e| e.is_a?(Class)}.first
|
55
|
+
data_model = a.select{|e| e.is_a?(Class)}.last
|
56
|
+
else
|
57
|
+
focus_model = data_model = a
|
58
|
+
end
|
59
|
+
|
60
|
+
line = QueryLine.new(models_path, access_filter)
|
61
|
+
line.ids_rel.join_on_path_thru([focus_model, data_model])
|
62
|
+
line.ids_rel.apply_condition data_model.arel_primary_key.not_eq(nil)
|
63
|
+
agg_only_lines << line
|
64
|
+
end
|
50
65
|
end
|
51
66
|
end
|
67
|
+
@lines += agg_only_lines
|
52
68
|
end
|
53
69
|
|
54
70
|
def run(cond = nil)
|
data/test/unit/query_test.rb
CHANGED
@@ -457,6 +457,21 @@ describe Mochigome::Query do
|
|
457
457
|
(data_node/0/0)['Gross'].to_f.to_s
|
458
458
|
end
|
459
459
|
|
460
|
+
it "shows aggregate data for mid-layer-tree models with no leaf model results" do
|
461
|
+
q = Mochigome::Query.new(
|
462
|
+
[Product, Category],
|
463
|
+
:aggregate_sources => {
|
464
|
+
[:report, Product] => [Sale]
|
465
|
+
}
|
466
|
+
)
|
467
|
+
dn = q.run
|
468
|
+
assert_equal 5, dn.children.size
|
469
|
+
assert_equal "Product A", (dn/0).name
|
470
|
+
assert_equal "Product E", (dn/4).name
|
471
|
+
assert_empty (dn/4).children
|
472
|
+
assert_equal 1, (dn/4)["Sales count"]
|
473
|
+
end
|
474
|
+
|
460
475
|
it "can do conditional counts" do
|
461
476
|
q = Mochigome::Query.new(
|
462
477
|
[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:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 5
|
10
|
+
version: 0.2.5
|
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-
|
18
|
+
date: 2012-11-01 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|