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

add functions that check for availaibility of spree components like b… #11847

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

Conversation

wjwitek
Copy link
Contributor

@wjwitek wjwitek commented Feb 10, 2023

…ackend, frontend

Move functions that check if different spree components are available out of spree_auth_device, becouse that's not the only place where we will need to do it, and it should be the same function used across spree.
See also:
spree/spree_auth_devise#578

@viezly
Copy link

viezly bot commented Feb 10, 2023

Changes preview:

Legend:

👀 Review pull request on Viezly

module Spree
module Core
module ControllerHelpers
module GemChecking
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a name like ComponentAvailability (I don't like this one 100% but maybe there's something similar) would be more clear here?

extend ActiveSupport::Concern

def backend_available?
@backend_available ||= Gem::Specification.find_all_by_name('spree_backend').any?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also do:

Suggested change
@backend_available ||= Gem::Specification.find_all_by_name('spree_backend').any?
@backend_available ||= Gem.loaded_specs.keys.include?('spree_backend')

But regardless, there is a potential issue here I think - this will return true when the Gem itself is present but it's not required anywhere i.e. it's in the Gemfile but not loaded into the application (I don't remember the semantics here but I'm pretty sure this is how it behaves). In that case, we say that something is available while it's not.

This shouldn't be an issue for most cases but I wouldn't be surprised if it yields something unexpected for some obscure use case. Probably that's why originally the functions checked whether the engines were loaded. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment it's done using:
::Rails::Engine.subclasses.map(&:instance).map { |e| e.class.to_s }.include?('Spree::Backend::Engine')
The reason for changing it to Gem is becouse we had some issues in the past with this way of checking in spree_auth_devise meaning that the order of gems in Gemfile had to be correct or it wouldn't work, which is not ideal.
I don't think it was ever an issue in spree_spree though, so maybe if spree_auth_devise uses functions provided by spree core it wouldn't be an issue (I could test it, try changing order of gems etc.).
Also I think those functions in spree_auth_devise were copied from here: https://github.com/spree/spree/blob/main/core/lib/spree/core/components.rb so I think we can just use that insted of moving it to controller helper.

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.

None yet

2 participants