File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 16
16
17
17
module Subroutine
18
18
19
+ # Used by polymorphic association fields to resolve the class name to a ruby class
20
+ def constantize_polymorphic_class_name ( class_name )
21
+ return @constantize_polymorphic_class_name . call ( class_name ) if defined? ( @constantize_polymorphic_class_name )
22
+
23
+ class_name . camelize . constantize
24
+ end
25
+
26
+ # When you need to customize how a polymorphic class name is resolved, you can set this callable/lambda/proc
27
+ def constantize_polymorphic_class_name = ( callable )
28
+ @constantize_polymorphic_class_name = callable
29
+ end
30
+
19
31
def self . include_defaults_in_params = ( bool )
20
32
@include_defaults_in_params = !!bool
21
33
end
Original file line number Diff line number Diff line change @@ -177,7 +177,7 @@ def fetch_association_instance(config)
177
177
get_field ( config . foreign_type_method )
178
178
end
179
179
180
- klass = klass . camelize . constantize if klass . is_a? ( String )
180
+ klass = Subroutine . constantize_polymorphic_class_name ( klass ) if klass . is_a? ( String )
181
181
return nil unless klass
182
182
183
183
foreign_key = config . foreign_key_method
You can’t perform that action at this time.
0 commit comments