lib/solidus_admin/configuration.rb in solidus_admin-0.2.0 vs lib/solidus_admin/configuration.rb in solidus_admin-0.3.0
- old
+ new
@@ -1,16 +1,16 @@
# frozen_string_literal: true
require 'spree/preferences/configuration'
+require 'solidus_admin/component_registry'
module SolidusAdmin
# Configuration for the admin interface.
#
# Ensure requiring this file after the Rails application has been created,
# as some defaults depend on the application context.
class Configuration < Spree::Preferences::Configuration
- ComponentNotFoundError = Class.new(NameError)
ENGINE_ROOT = File.expand_path("#{__dir__}/../..")
# Path to the logo used in the admin interface.
#
# It needs to be a path to an image file accessible by Sprockets.
@@ -110,17 +110,10 @@
}
]
},
{
- key: "promotions",
- route: -> { spree.admin_promotions_path },
- icon: "megaphone-line",
- position: 30,
- },
-
- {
key: "stock",
route: -> { spree.admin_stock_items_path },
icon: "stack-line",
position: 40
},
@@ -185,27 +178,10 @@
@menu_items = Spree::Backend::Config.menu_items.map.with_index(&menu_item_to_hash)
end
def components
- @components ||= Hash.new do |_h, k|
- 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
+ @components ||= ComponentRegistry.new
end
# The method used to authenticate the user in the admin interface, it's expected to redirect the user to the login method
# in case the authentication fails.
preference :authentication_method, :string, default: :authenticate_solidus_backend_user!