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

backport: Dependency Resolver Extends to change gem loading #60

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Application < Rails::Application

config.after_initialize do
require "extends/controllers/decidim/devise/sessions_controller_extends"
require "extends/lib/decidim/dependency_resolver_extends"

Decidim::GraphiQL::Rails.config.tap do |config|
config.initial_query = "{\n deployment {\n version\n branch\n remote\n upToDate\n currentCommit\n latestCommit\n locallyModified\n }\n}".html_safe
Expand Down
29 changes: 29 additions & 0 deletions lib/extends/lib/decidim/dependency_resolver_extends.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

# Backport from https://github.com/decidim/decidim/pull/12061/files
# Related to : https://github.com/decidim/decidim/issues/11636
module DependencyResolverExtends
# Finds a gem specification from the locked gems of the instance.
#
# Note that this does not resolve if the module is needed or not. This may
# also return the gem specification even when it is not listed in the
# Gemfile, e.g. when the Decidim gems are installed through git.
#
# @param name [String] The name of the gem to find.
# @return [Bundler::LazySpecification, nil] The specification for the gem
# or nil if the gem is not listed in the locked gems.
def spec(name)
sp = Bundler.definition.locked_gems.specs.find { |s| s.name == name }

# Fetching the gem through Gem.loaded_specs ensures we are not returning
# a lazy specification which does not respond to `#full_gem_path` which
# is needed for the resolver.
return Gem.loaded_specs[sp.name] if sp

nil
end
end

Decidim::DependencyResolver::Lookup.class_eval do
prepend(DependencyResolverExtends)
end
Loading