mochigome 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mochigome_ver.rb +1 -1
- data/lib/query.rb +20 -12
- data/lib/relation.rb +11 -6
- metadata +4 -4
data/lib/mochigome_ver.rb
CHANGED
data/lib/query.rb
CHANGED
@@ -60,12 +60,21 @@ module Mochigome
|
|
60
60
|
|
61
61
|
def self.tree_root_to_leaf_paths(t)
|
62
62
|
if t.is_a?(Hash)
|
63
|
+
unless t.size == 1 && t.keys.first.acts_as_mochigome_focus?
|
64
|
+
raise QueryError.new "Invalid layer tree hash #{t}"
|
65
|
+
end
|
63
66
|
t.map{|k, v|
|
64
67
|
tree_root_to_leaf_paths(v).map{|p| [k] + p}
|
65
68
|
}.flatten(1)
|
66
69
|
elsif t.is_a?(Array)
|
70
|
+
unless t.all?{|e| e.is_a?(Hash) || e.acts_as_mochigome_focus?}
|
71
|
+
raise QueryError.new "Invalid layer tree array #{t}"
|
72
|
+
end
|
67
73
|
t.map{|v| tree_root_to_leaf_paths(v)}.flatten(1)
|
68
74
|
else
|
75
|
+
unless t.acts_as_mochigome_focus?
|
76
|
+
raise QueryError.new "Invalid layer tree element #{t}"
|
77
|
+
end
|
69
78
|
[[t]]
|
70
79
|
end
|
71
80
|
end
|
@@ -117,18 +126,17 @@ module Mochigome
|
|
117
126
|
|
118
127
|
def create_root_node
|
119
128
|
root = DataNode.new(:report, @name)
|
120
|
-
root.comment =
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
return root
|
129
|
+
root.comment = "Mochigome Version: #{Mochigome::VERSION}\n"
|
130
|
+
root.comment += "Report Generated: #{Time.now}\n"
|
131
|
+
@lines.each_with_index do |line, i|
|
132
|
+
root.comment += "Query Line #{i+1}:\n"
|
133
|
+
root.comment += " #{line.layer_types.map(&:name).join("=>")}\n"
|
134
|
+
root.comment += " Join Paths:\n"
|
135
|
+
line.ids_rel.join_path_descriptions.each do |d|
|
136
|
+
root.comment += " #{d}\n"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
return root
|
132
140
|
end
|
133
141
|
end
|
134
142
|
|
data/lib/relation.rb
CHANGED
@@ -2,7 +2,7 @@ module Mochigome
|
|
2
2
|
private
|
3
3
|
|
4
4
|
class Relation
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :spine_layers, :join_path_descriptions
|
6
6
|
|
7
7
|
def initialize(layers)
|
8
8
|
@model_graph = ModelGraph.new
|
@@ -10,7 +10,7 @@ module Mochigome
|
|
10
10
|
@models = Set.new
|
11
11
|
@model_join_stack = []
|
12
12
|
@spine = []
|
13
|
-
@
|
13
|
+
@join_path_descriptions = []
|
14
14
|
|
15
15
|
@spine_layers.map(&:to_real_model).uniq.each do |m|
|
16
16
|
join_to_model(m)
|
@@ -54,12 +54,14 @@ module Mochigome
|
|
54
54
|
raise QueryError.new("No path to #{model}") unless best_path
|
55
55
|
join_on_path(best_path)
|
56
56
|
|
57
|
-
# Also use the conditions of any other path
|
57
|
+
# Also use the conditions of any other unique path
|
58
58
|
# TODO: Write a test that requires the below code to work
|
59
59
|
@models.reject{|n| best_path.include?(n)}.each do |n|
|
60
60
|
extra_path = @model_graph.path_thru([n, model])
|
61
|
-
if extra_path
|
62
|
-
|
61
|
+
if extra_path
|
62
|
+
unless best_path.all?{|m| extra_path.include?(m)}
|
63
|
+
join_on_path extra_path
|
64
|
+
end
|
63
65
|
end
|
64
66
|
end
|
65
67
|
end
|
@@ -77,13 +79,17 @@ module Mochigome
|
|
77
79
|
begin
|
78
80
|
path = path.map(&:to_real_model).uniq
|
79
81
|
join_to_model path.first
|
82
|
+
join_descrips = [path.first.name]
|
80
83
|
(0..(path.size-2)).map{|i| [path[i], path[i+1]]}.each do |src, tgt|
|
81
84
|
if @models.include?(tgt)
|
82
85
|
apply_condition(@model_graph.edge_condition(src, tgt))
|
86
|
+
join_descrips << "*#{tgt.name}"
|
83
87
|
else
|
84
88
|
add_join_link(src, tgt)
|
89
|
+
join_descrips << tgt.name
|
85
90
|
end
|
86
91
|
end
|
92
|
+
@join_path_descriptions << join_descrips.join("->")
|
87
93
|
rescue QueryError => e
|
88
94
|
raise QueryError.new("Error pathing #{path.map(&:name).inspect}: #{e}")
|
89
95
|
end
|
@@ -154,7 +160,6 @@ module Mochigome
|
|
154
160
|
@model_join_stack.pop
|
155
161
|
end
|
156
162
|
|
157
|
-
@joins << [src, tgt]
|
158
163
|
@models.add tgt
|
159
164
|
end
|
160
165
|
|
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: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
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-09-
|
18
|
+
date: 2012-09-27 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|