Skip to content

Commit 4ac5903

Browse files
committed
Extract method to make codeclimate happy
1 parent a40938f commit 4ac5903

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/rails_erd/domain.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,7 @@ def check_association_validity(association)
140140
association.check_validity!
141141

142142
if association.options[:polymorphic]
143-
entity_name = association.class_name
144-
entity = entity_by_name(entity_name)
145-
if entity.nil? || entity.generalized?
146-
raise "polymorphic interface #{entity_name} does not exist"
147-
end
143+
check_polymorphic_association_validity(association)
148144
else
149145
entity_name = association.klass.name # Raises NameError if the associated class cannot be found.
150146
entity_by_name(entity_name) or raise "model #{entity_name} exists, but is not included in domain"
@@ -153,6 +149,14 @@ def check_association_validity(association)
153149
warn "Ignoring invalid association #{association_description(association)} (#{e.message})"
154150
end
155151

152+
def check_polymorphic_association_validity(association)
153+
entity_name = association.class_name
154+
entity = entity_by_name(entity_name)
155+
if entity.nil? || entity.generalized?
156+
raise "polymorphic interface #{entity_name} does not exist"
157+
end
158+
end
159+
156160
def association_description(association)
157161
"#{association.name.inspect} on #{association.active_record}"
158162
end

0 commit comments

Comments
 (0)