Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use #constantize for configurable class lists #1203

Merged
merged 6 commits into from
Jun 1, 2016

Conversation

jhawthorn
Copy link
Contributor

In solidus, we have a Spree::Core::Environment class. This class is what's exposed as config.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 by to_sing anything being inserted into the list, and constantizeing 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.

@jhawthorn jhawthorn force-pushed the class_constantizer branch from a80ca68 to 035afd6 Compare May 30, 2016 18:37
jhawthorn added 5 commits May 30, 2016 12:57
This class is responsible for holding as set of references to classes
(by their name). This is done instead of just having the classes to
avoid loading the classes too early as well as to allow code reloading
of these classes.
This avoids loading the classes sooner than needed.

This should fix issues where, for example, PaymentMethod is loaded
before acts_as_list has its initializer run.
Previously promotion rules were added to the configuration after all
initialization to avoid issues. Now we are able to add the class names
at the normal time.

This will also allow a store to remove a rule if desired.
@jhawthorn jhawthorn force-pushed the class_constantizer branch from 035afd6 to e329a56 Compare May 30, 2016 20:00
@gmacdougall
Copy link
Member

I think this is a great change in the right direction. It probably deserves a place in the Changelog.

@cbrunsdon
Copy link
Contributor

I caught the live show of this and am inherently 👍.

Not just because it is @jhawthorn wandering around fixing problems I am having, but also because if its @jhawthorn wandering around actively fixing my mistakes.

@gmacdougall
Copy link
Member

👍

@jrochkind
Copy link
Contributor

Is this ready to merge? Does it close #1192 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants