Skip to content

Commit

Permalink
Merge pull request #5432 from solidusio/elia/admin/component-name-error
Browse files Browse the repository at this point in the history
Don't capture `NameError` if its not a missing component
  • Loading branch information
elia authored Oct 12, 2023
2 parents afc630e + 336a0c1 commit 870e9bf
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions admin/lib/solidus_admin/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,22 @@ def menu_items

def components
@components ||= Hash.new do |_h, k|
"solidus_admin/#{k}/component".classify.constantize
rescue NameError
prefix = "#{ENGINE_ROOT}/app/components/solidus_admin/"
suffix = "/component.rb"
dictionary = Dir["#{prefix}**#{suffix}"].map { _1.delete_prefix(prefix).delete_suffix(suffix) }
corrections = DidYouMean::SpellChecker.new(dictionary: dictionary).correct(k.to_s)

raise ComponentNotFoundError, "Unknown component #{k}#{DidYouMean.formatter.message_for(corrections)}"
const_name = "solidus_admin/#{k}/component".classify

unless Object.const_defined?(const_name)
prefix = "#{ENGINE_ROOT}/app/components/solidus_admin/"
suffix = "/component.rb"
dictionary = Dir["#{prefix}**#{suffix}"].map { _1.delete_prefix(prefix).delete_suffix(suffix) }
corrections = DidYouMean::SpellChecker.new(dictionary: dictionary).correct(k.to_s)

raise ComponentNotFoundError.new(
"Unknown component #{k}#{DidYouMean.formatter.message_for(corrections)}",
k.classify,
receiver: ::SolidusAdmin
)
end

const_name.constantize
end
end

Expand Down

0 comments on commit 870e9bf

Please sign in to comment.