Skip to content

Commit 98c81ef

Browse files
committed
Use safe_constantize instead
Plus, use `nil?` to be idiomatic.
1 parent eabed58 commit 98c81ef

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

lib/polymorphic_integer_type/extensions.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,9 @@ def remove_type_and_establish_mapping(name, options, scope)
8484
end
8585

8686
def retrieve_polymorphic_type_mapping(polymorphic_type:, class_name:)
87-
return if polymorphic_type == nil
88-
89-
belongs_to_class = begin
90-
class_name.constantize
91-
rescue NameError
92-
# Class not found
93-
end
87+
return if polymorphic_type.nil?
9488

89+
belongs_to_class = class_name.safe_constantize
9590
method_name = "#{polymorphic_type}_type_mapping"
9691

9792
if belongs_to_class && belongs_to_class.respond_to?(method_name)

0 commit comments

Comments
 (0)