Skip to content

Commit

Permalink
Merge pull request #53 from kgleong/add-controller-group-blacklist
Browse files Browse the repository at this point in the history
Ensure the required Spree engines are included before decorating classes.
  • Loading branch information
adammathys authored Jul 7, 2016
2 parents 83f2d3b + 50dc1c1 commit 00539d4
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/controllers/spree/admin/products_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
update.before :set_stores

private

def set_stores
# Remove all store associations if store data is being passed and no stores are selected
if params[:update_store_ids] && !params[:product].key?(:store_ids)
@product.stores.clear
end
end

end
end if SpreeMultiDomain::Engine.admin_available?
4 changes: 3 additions & 1 deletion app/controllers/spree/api/line_items_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Spree::Api::LineItemsController.include SpreeMultiDomain::CreateLineItemSupport
if SpreeMultiDomain::Engine.api_available?
Spree::Api::LineItemsController.include(SpreeMultiDomain::CreateLineItemSupport)
end
4 changes: 3 additions & 1 deletion app/controllers/spree/api/products_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Spree::Api::ProductsController.include(SpreeMultiDomain::ShowProductSupport)
if SpreeMultiDomain::Engine.api_available?
Spree::Api::ProductsController.include(SpreeMultiDomain::ShowProductSupport)
end
6 changes: 4 additions & 2 deletions app/controllers/spree/api/shipments_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ def mine_with_store_scope
end
end

Spree::Api::ShipmentsController.include SpreeMultiStore::Api::ShipmentsControllerDecorator
Spree::Api::ShipmentsController.include SpreeMultiDomain::CreateLineItemSupport
if SpreeMultiDomain::Engine.api_available?
Spree::Api::ShipmentsController.include(SpreeMultiStore::Api::ShipmentsControllerDecorator)
Spree::Api::ShipmentsController.include(SpreeMultiDomain::CreateLineItemSupport)
end
2 changes: 1 addition & 1 deletion app/controllers/spree/home_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ def index
@products = @searcher.retrieve_products
@taxonomies = get_taxonomies
end
end
end if SpreeMultiDomain::Engine.frontend_available?
4 changes: 3 additions & 1 deletion app/controllers/spree/products_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Spree::ProductsController.include(SpreeMultiDomain::ShowProductSupport)
if SpreeMultiDomain::Engine.frontend_available?
Spree::ProductsController.include(SpreeMultiDomain::ShowProductSupport)
end
2 changes: 1 addition & 1 deletion app/controllers/spree/taxons_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ def show
@products = @searcher.retrieve_products
@taxonomies = get_taxonomies
end
end
end if SpreeMultiDomain::Engine.frontend_available?
26 changes: 20 additions & 6 deletions lib/spree_multi_domain/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,29 @@ class Engine < Rails::Engine

config.autoload_paths += %W(#{config.root}/lib)

def self.activate
['app', 'lib'].each do |dir|
Dir.glob(File.join(File.dirname(__FILE__), "../../#{dir}/**/*_decorator*.rb")) do |c|
Rails.application.config.cache_classes ? require(c) : load(c)
class << self
def activate
['app', 'lib'].each do |dir|
Dir.glob(File.join(File.dirname(__FILE__), "../../#{dir}/**/*_decorator*.rb")) do |c|
Rails.application.config.cache_classes ? require(c) : load(c)
end
end

Spree::Config.searcher_class = Spree::Search::MultiDomain
ApplicationController.send :include, SpreeMultiDomain::MultiDomainHelpers
end

def admin_available?
const_defined?('Spree::Backend::Engine')
end

Spree::Config.searcher_class = Spree::Search::MultiDomain
ApplicationController.send :include, SpreeMultiDomain::MultiDomainHelpers
def api_available?
const_defined?('Spree::Api::Engine')
end

def frontend_available?
const_defined?('Spree::Frontend::Engine')
end
end

config.to_prepare &method(:activate).to_proc
Expand Down

0 comments on commit 00539d4

Please sign in to comment.