lib/spree/auth/engine.rb in solidus_auth_devise-1.4.0 vs lib/spree/auth/engine.rb in solidus_auth_devise-1.5.0
- old
+ new
@@ -5,15 +5,15 @@
module Auth
class Engine < Rails::Engine
isolate_namespace Spree
engine_name 'solidus_auth'
- initializer "spree.auth.environment", :before => :load_config_initializers do |app|
+ initializer "spree.auth.environment", before: :load_config_initializers do |app|
Spree::Auth::Config = Spree::AuthConfiguration.new
end
- initializer "solidus_auth_devise.set_user_class", :after => :load_config_initializers do
+ initializer "solidus_auth_devise.set_user_class", after: :load_config_initializers do
Spree.user_class = "Spree::User"
end
initializer "solidus_auth_devise.check_secret_token" do
if Spree::Auth.default_secret_key == Devise.secret_key
@@ -22,77 +22,80 @@
puts " "
puts %Q{Devise.secret_key = "#{SecureRandom.hex(50)}"}
end
end
- def self.activate
- if Spree::Auth::Engine.backend_available?
- Rails.application.config.assets.precompile += [
- 'lib/assets/javascripts/spree/backend/solidus_auth.js',
- 'lib/assets/javascripts/spree/backend/solidus_auth.css'
- ]
- Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/backend/*/*/*_decorator*.rb")) do |c|
- Rails.configuration.cache_classes ? require(c) : load(c)
- end
+ config.to_prepare do
+ auth = Spree::Auth::Engine
+
+ auth.prepare_backend if auth.backend_available?
+ auth.prepare_frontend if auth.frontend_available?
+
+ ApplicationController.send :include, Spree::AuthenticationHelpers
+ end
+
+ def self.prepare_backend
+ Rails.application.config.assets.precompile += %w[
+ lib/assets/javascripts/spree/backend/solidus_auth.js
+ lib/assets/javascripts/spree/backend/solidus_auth.css
+ ]
+
+ Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/backend/*/*/*_decorator*.rb")) do |c|
+ Rails.configuration.cache_classes ? require(c) : load(c)
end
- if Spree::Auth::Engine.frontend_available?
- Rails.application.config.assets.precompile += [
- 'lib/assets/javascripts/spree/frontend/solidus_auth.js',
- 'lib/assets/javascripts/spree/frontend/solidus_auth.css'
- ]
- Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/frontend/*/*_decorator*.rb")) do |c|
- Rails.configuration.cache_classes ? require(c) : load(c)
+
+ Spree::Admin::BaseController.unauthorized_redirect = -> do
+ if try_spree_current_user
+ flash[:error] = Spree.t(:authorization_failure)
+ redirect_to spree.admin_unauthorized_path
+ else
+ store_location
+ redirect_to spree.admin_login_path
end
end
- ApplicationController.send :include, Spree::AuthenticationHelpers
+ end
- if self.frontend_available?
- Spree::BaseController.unauthorized_redirect = -> do
- if try_spree_current_user
- flash[:error] = Spree.t(:authorization_failure)
- redirect_to spree.unauthorized_path
- else
- store_location
- redirect_to spree.login_path
- end
- end
+ def self.prepare_frontend
+ Rails.application.config.assets.precompile += %w[
+ lib/assets/javascripts/spree/frontend/solidus_auth.js
+ lib/assets/javascripts/spree/frontend/solidus_auth.css
+ ]
+
+ Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/frontend/*/*_decorator*.rb")) do |c|
+ Rails.configuration.cache_classes ? require(c) : load(c)
end
- if self.backend_available?
- Spree::Admin::BaseController.unauthorized_redirect = -> do
- if try_spree_current_user
- flash[:error] = Spree.t(:authorization_failure)
- redirect_to spree.admin_unauthorized_path
- else
- store_location
- redirect_to spree.admin_login_path
- end
+ Spree::BaseController.unauthorized_redirect = -> do
+ if try_spree_current_user
+ flash[:error] = Spree.t(:authorization_failure)
+ redirect_to spree.unauthorized_path
+ else
+ store_location
+ redirect_to spree.login_path
end
end
end
def self.backend_available?
- @@backend_available ||= ::Rails::Engine.subclasses.map(&:instance).map{ |e| e.class.to_s }.include?('Spree::Backend::Engine')
+ defined?(Spree::Backend::Engine) == "constant"
end
def self.dash_available?
- @@dash_available ||= ::Rails::Engine.subclasses.map(&:instance).map{ |e| e.class.to_s }.include?('Spree::Dash::Engine')
+ defined?(Spree::Dash::Engine) == "constant"
end
def self.frontend_available?
- @@frontend_available ||= ::Rails::Engine.subclasses.map(&:instance).map{ |e| e.class.to_s }.include?('Spree::Frontend::Engine')
+ defined?(Spree::Frontend::Engine) == "constant"
end
- if self.backend_available?
+ if backend_available?
paths["app/controllers"] << "lib/controllers/backend"
paths["app/views"] << "lib/views/backend"
end
- if self.frontend_available?
+ if frontend_available?
paths["app/controllers"] << "lib/controllers/frontend"
paths["app/views"] << "lib/views/frontend"
end
-
- config.to_prepare &method(:activate).to_proc
end
end
end