Skip to content

Commit 7567f6f

Browse files
committed
Merge pull request #103 from kerrizor/avoid-null-objects-in-sort
Use NullObjects to avoid bug where generalized or specialization could b...
2 parents d4f607e + e197e1d commit 7567f6f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/rails_erd/domain/specialization.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def abstract_from_models(domain, models)
4949
attr_reader :specialized
5050

5151
def initialize(domain, generalized, specialized) # @private :nodoc:
52-
@domain, @generalized, @specialized = domain, generalized, specialized
52+
@domain = domain
53+
@generalized = generalized || NullGeneralized.new
54+
@specialized = specialized || NullSpecialization.new
5355
end
5456

5557
def generalization?
@@ -66,5 +68,17 @@ def <=>(other) # @private :nodoc:
6668
(generalized.name <=> other.generalized.name).nonzero? or (specialized.name <=> other.specialized.name)
6769
end
6870
end
71+
72+
class NullSpecialization
73+
def name
74+
""
75+
end
76+
end
77+
78+
class NullGeneralized
79+
def name
80+
""
81+
end
82+
end
6983
end
7084
end

0 commit comments

Comments
 (0)