Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Use module_eval to override link_to_cart in Solidus Demo #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gsmendoza
Copy link
Contributor

@gsmendoza gsmendoza commented Jan 12, 2022

Goal

As a Solidus Demo contributor

I would like to use module_eval to override link_to_cart

So that we can ensure that the Spree::BaseHelper engine module is
reopened by Solidus Demo, which according to
https://guides.rubyonrails.org/engines.html#improving-engine-functionality,
is necessary for overriding the engine module.

Basis

From
https://guides.rubyonrails.org/engines.html#improving-engine-functionality:

It is very important that the override reopens the class or module.
Using the class or module keywords would define them if they were not
already in memory, which would be incorrect because the definition lives
in the engine. Using class_eval as shown above ensures you are
reopening.

Demo

https://www.loom.com/share/f1193e1d0583435e83db43f9f1a27da6

@gsmendoza gsmendoza force-pushed the gsmendoza/eng-283-use-class_eval-to-override-link_to_cart branch from 766b506 to 4f74958 Compare January 12, 2022 08:33
Goal
----

As a Solidus Demo contributor

I would like to use `module_eval` to override `link_to_cart`

So that we can ensure that the `Spree::BaseHelper` engine module is
reopened by Solidus Demo, which according to
https://guides.rubyonrails.org/engines.html#improving-engine-functionality,
is necessary for overriding the engine module.

Basis
-----

From
https://guides.rubyonrails.org/engines.html#improving-engine-functionality:

> It is very important that the override reopens the class or module.
Using the class or module keywords would define them if they were not
already in memory, which would be incorrect because the definition lives
in the engine. Using `class_eval` as shown above ensures you are
reopening.
@gsmendoza gsmendoza changed the title Use class_eval to override link_to_cart in Solidus Demo Use module_eval to override link_to_cart in Solidus Demo Jan 12, 2022
@gsmendoza gsmendoza force-pushed the gsmendoza/eng-283-use-class_eval-to-override-link_to_cart branch from 4f74958 to 7d8d489 Compare January 12, 2022 09:06
@kennyadsl
Copy link
Member

Why not create a new helper for the application that contains a helper function with the same name instead? I think cart_link will be overridden without the need to open the existing module.

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

Successfully merging this pull request may close these issues.

2 participants