Use #constantize for configurable class lists #1203
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In solidus, we have a
Spree::Core::Environment
class. This class is what's exposed asconfig.spree
in initializers and holds mostly configuration on available classes:shipping_methods
,payment_methods
,promotion_rules
, etc.This has caused some weird issues for quite a while since these classes are put into an array at compile time. If any of these classes are reloaded (as they will be in development) the configuration will hold an out of date version. #899 is an example of an issue arising from this.
This PR adds a
ClassConstantizer::Set
collection to hold these lists of classes. It works byto_s
ing anything being inserted into the list, andconstantize
ing them when the list is iterated over. This should be backwards compatible for common ways to insert .This also solves issues caused by autoloading classes too early (#1192)
For the same reasons as this activerecord relations hold
class_name
instead of just a class. Our UserClassHandle also serves a similar purpose.