stepford 0.9.0 → 0.9.1

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.
@@ -4,7 +4,9 @@ module Stepford
4
4
  @@model_and_association_names = []
5
5
  @@level = 0
6
6
  @@offenders = []
7
+ @@circles_sorted = []
7
8
  @@circles = []
9
+ @@selected_offenders = []
8
10
 
9
11
  # Check refs on all models or models specified in comma delimited list in options like:
10
12
  # Stepford.CircularRefChecker.check_refs models: 'user, post, comment'
@@ -31,11 +33,18 @@ module Stepford
31
33
  end
32
34
  puts
33
35
  puts
34
- puts "Possible offenders. Either set nullable to true on these fields, or see if any of the fields above can be nullable:"
36
+ puts "All foreign keys involved in a circular dependency:"
35
37
  puts
36
38
  @@offenders.sort.each do |c|
37
39
  puts "#{c[0]}.#{c[1]}"
38
40
  end
41
+ puts
42
+ puts
43
+ puts "Arbitrarily chosen foreign_keys involved in a circular dependency that would break each circular dependency chain if marked as nullable. It would be a better idea to examine the full list of foreign keys and circles above, fix, then rerun:"
44
+ puts
45
+ @@selected_offenders.sort.each do |c|
46
+ puts "#{c[0]}.#{c[1]}"
47
+ end
39
48
 
40
49
  return (@@offenders.size == 0)
41
50
  end
@@ -45,6 +54,7 @@ module Stepford
45
54
 
46
55
  model_class.reflections.collect {|association_name, reflection|
47
56
  @@model_and_association_names = [] if @@level == 1
57
+ next unless reflection.macro == :belongs_to
48
58
  assc_sym = reflection.name.to_sym
49
59
  clas_sym = reflection.class_name.underscore.to_sym
50
60
 
@@ -55,14 +65,16 @@ module Stepford
55
65
  key = [model_class.to_s.underscore.to_sym, assc_sym]
56
66
  if @@model_and_association_names.include?(key)
57
67
  @@offenders << @@model_and_association_names.last unless @@offenders.include?(@@model_and_association_names.last)
58
- # add to end
59
- @@model_and_association_names << key
60
68
  short = @@model_and_association_names.dup
61
69
  # drop all preceding keys that have nothing to do with the circle
62
70
  (short.index(key)).times {short.delete_at(0)}
63
- string_representation = "#{short.collect{|b|"#{b[0]}.#{b[1]}"}.join(' -> ')}"
64
- #puts string_representation
65
- @@circles << string_representation.to_sym unless @@circles.include?(string_representation.to_sym)
71
+ sorted = short.sort
72
+ unless @@circles_sorted.include?(sorted)
73
+ @@circles_sorted << sorted
74
+ last_key_in_circle_before_restart = short.last
75
+ @@selected_offenders << last_key_in_circle_before_restart unless @@selected_offenders.include?(last_key_in_circle_before_restart)
76
+ @@circles << "#{(short << key).collect{|b|"#{b[0]}.#{b[1]}"}.join(' -> ')}".to_sym
77
+ end
66
78
  else
67
79
  @@model_and_association_names << key
68
80
  check_associations(reflection.class_name.constantize)
@@ -1,3 +1,3 @@
1
1
  module Stepford
2
- VERSION = '0.9.0'
2
+ VERSION = '0.9.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stepford
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-08 00:00:00.000000000 Z
12
+ date: 2012-11-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor