mochigome 0.2.3 → 0.2.4
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/model_graph.rb +33 -29
- metadata +4 -4
data/lib/mochigome_ver.rb
CHANGED
data/lib/model_graph.rb
CHANGED
@@ -170,6 +170,8 @@ module Mochigome
|
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
|
+
preferred_paths = {}
|
174
|
+
|
173
175
|
added_models.each do |model|
|
174
176
|
ignore_assocs, model_preferred_paths = [], {}
|
175
177
|
if model.acts_as_mochigome_focus?
|
@@ -178,8 +180,6 @@ module Mochigome
|
|
178
180
|
model_preferred_paths = opts[:preferred_paths]
|
179
181
|
end
|
180
182
|
|
181
|
-
preferred_paths = {}
|
182
|
-
|
183
183
|
# Use through reflections as a hint for preferred indirect paths
|
184
184
|
# TODO Support for nested through reflections
|
185
185
|
# (Though Rails 2 doesn't support them either...)
|
@@ -192,7 +192,8 @@ module Mochigome
|
|
192
192
|
foreign_model = assoc.klass
|
193
193
|
join_model = assoc.through_reflection.klass
|
194
194
|
rescue NameError
|
195
|
-
# FIXME Can't handle polymorphic through reflection
|
195
|
+
# FIXME Can't handle polymorphic through reflection, skip for now
|
196
|
+
next
|
196
197
|
end
|
197
198
|
edge = [model, foreign_model]
|
198
199
|
path = [model, join_model, foreign_model]
|
@@ -219,35 +220,38 @@ module Mochigome
|
|
219
220
|
sub_link = @shortest_paths[[model, assoc.klass]]
|
220
221
|
preferred_paths[edge] = sub_link + sub_path.drop(1)
|
221
222
|
end
|
223
|
+
end
|
222
224
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
@shortest_paths[re] = rp
|
225
|
+
# Replace all instances of the default path in the path directory
|
226
|
+
# with the preferred path, including when the default path is
|
227
|
+
# a subset of a larger path, and/or when the direction of travel
|
228
|
+
# is reversed.
|
229
|
+
# FIXME What if preferred paths conflict?
|
230
|
+
# FIXME What if one preferred path causes a shortest_path to become
|
231
|
+
# applicable under another one? Then arbitrary model scanning
|
232
|
+
# order matters, and it shouldn't. Is there even a consistent
|
233
|
+
# way to deal with this? Keep cycling through until we don't
|
234
|
+
# have any more replacements? Have to make sure not to cycle
|
235
|
+
# forever, though...
|
236
|
+
preferred_paths.keys.sort{|a,b| a.map(&:name) <=> b.map(&:name)}.each do |edge|
|
237
|
+
path = preferred_paths[edge]
|
238
|
+
[lambda{|a| a}, lambda{|a| a.reverse}].each do |prc|
|
239
|
+
e, p = prc.call(edge), prc.call(path)
|
240
|
+
old_path = @shortest_paths[e] or next
|
241
|
+
next if old_path == p
|
242
|
+
edges_to_replace = {}
|
243
|
+
@shortest_paths.each do |se, sp|
|
244
|
+
p_begin = sp.find_index(old_path.first)
|
245
|
+
if p_begin && sp[p_begin, old_path.size] == old_path
|
246
|
+
edges_to_replace[se] =
|
247
|
+
sp.take(p_begin) +
|
248
|
+
p +
|
249
|
+
sp.drop(p_begin + old_path.size)
|
249
250
|
end
|
250
251
|
end
|
252
|
+
edges_to_replace.each do |re, rp|
|
253
|
+
@shortest_paths[re] = rp
|
254
|
+
end
|
251
255
|
end
|
252
256
|
end
|
253
257
|
end
|
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: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 4
|
10
|
+
version: 0.2.4
|
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-10-
|
18
|
+
date: 2012-10-29 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|