Skip to content

Commit

Permalink
Use NullObjects to avoid bug where generalized or specialization coul…
Browse files Browse the repository at this point in the history
…d be null
  • Loading branch information
kerrizor committed Dec 19, 2014
1 parent d4f607e commit e197e1d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/rails_erd/domain/specialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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

0 comments on commit e197e1d

Please sign in to comment.