mochigome 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/mochigome_ver.rb +1 -1
  2. data/lib/model_graph.rb +33 -29
  3. metadata +4 -4
data/lib/mochigome_ver.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mochigome
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
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
- # Replace all instances of the default path in the path directory
224
- # with the preferred path, including when the default path is
225
- # a subset of a larger path, and/or when the direction of travel
226
- # is reversed.
227
- # FIXME What if preferred paths conflict?
228
- # FIXME What if one preferred path causes a shortest_path to become
229
- # applicable under another one? Then arbitrary model scanning
230
- # order matters, and it shouldn't. Is there even a consistent
231
- # way to deal with this?
232
- preferred_paths.each do |edge, path|
233
- [lambda{|a| a}, lambda{|a| a.reverse}].each do |prc|
234
- e, p = prc.call(edge), prc.call(path)
235
- old_path = @shortest_paths[e]
236
- next if old_path == p
237
- edges_to_replace = {}
238
- @shortest_paths.each do |se, sp|
239
- p_begin = sp.find_index(old_path.first)
240
- if p_begin && sp[p_begin, old_path.size] == old_path
241
- edges_to_replace[se] =
242
- sp.take(p_begin) +
243
- p +
244
- sp.drop(p_begin + old_path.size)
245
- end
246
- end
247
- edges_to_replace.each do |re, rp|
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: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
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-25 00:00:00 Z
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