From e197e1dbbb94ebefac7246a2a8e08752ce345773 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Thu, 18 Dec 2014 18:32:41 -0800 Subject: [PATCH] Use NullObjects to avoid bug where generalized or specialization could be null --- lib/rails_erd/domain/specialization.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/rails_erd/domain/specialization.rb b/lib/rails_erd/domain/specialization.rb index 4ee682b6..6938793c 100644 --- a/lib/rails_erd/domain/specialization.rb +++ b/lib/rails_erd/domain/specialization.rb @@ -49,7 +49,9 @@ def abstract_from_models(domain, models) attr_reader :specialized def initialize(domain, generalized, specialized) # @private :nodoc: - @domain, @generalized, @specialized = domain, generalized, specialized + @domain = domain + @generalized = generalized || NullGeneralized.new + @specialized = specialized || NullSpecialization.new end def generalization? @@ -66,5 +68,17 @@ def <=>(other) # @private :nodoc: (generalized.name <=> other.generalized.name).nonzero? or (specialized.name <=> other.specialized.name) end end + + class NullSpecialization + def name + "" + end + end + + class NullGeneralized + def name + "" + end + end end end