Skip to content

Commit

Permalink
Merge pull request #115 from mamhoff/rename-decorator-constants
Browse files Browse the repository at this point in the history
Use our namespace for decorator constant
  • Loading branch information
tvdeyen authored Nov 22, 2024
2 parents 8704410 + e8e8106 commit 4146f1c
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 69 deletions.
29 changes: 29 additions & 0 deletions app/decorators/models/alchemy/solidus/spree_product_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module Alchemy
module Solidus
module SpreeProductDecorator
def self.prepended(base)
base.include Alchemy::Solidus::TouchAlchemyIngredients
base.has_many :alchemy_ingredients, class_name: "Alchemy::Ingredients::SpreeProduct", as: :related_object, dependent: :nullify
end

private

# Overwritten Solidus' default behavior
#
# The Solidus implementation did not trigger `touch` on taxons, but
# updated the `updated_at` timestamp in an `update_all`.
#
# Since we want to invalidate ingredient spree taxons cache as well
# we need to use `touch` here and use the `after_touch` callback of
# Spree::Taxon
#
def touch_taxons
taxons.each(&:touch)
end

::Spree::Product.prepend self
end
end
end
14 changes: 14 additions & 0 deletions app/decorators/models/alchemy/solidus/spree_taxon_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Alchemy
module Solidus
module SpreeTaxonDecorator
def self.prepended(base)
base.include Alchemy::Solidus::TouchAlchemyIngredients
base.has_many :alchemy_ingredients, class_name: "Alchemy::Ingredients::SpreeTaxon", as: :related_object, dependent: :nullify
end

::Spree::Taxon.prepend self
end
end
end
14 changes: 14 additions & 0 deletions app/decorators/models/alchemy/solidus/spree_variant_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Alchemy
module Solidus
module SpreeVariantDecorator
def self.prepended(base)
base.include Alchemy::Solidus::TouchAlchemyIngredients
base.has_many :alchemy_ingredients, class_name: "Alchemy::Ingredients::SpreeVariant", as: :related_object, dependent: :nullify
end

::Spree::Variant.prepend self
end
end
end
27 changes: 0 additions & 27 deletions app/decorators/models/spree/spree_product_decorator.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/decorators/models/spree/spree_taxon_decorator.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/decorators/models/spree/spree_variant_decorator.rb

This file was deleted.

20 changes: 20 additions & 0 deletions app/models/alchemy/solidus/touch_alchemy_ingredients.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Alchemy
module Solidus
module TouchAlchemyIngredients
extend ActiveSupport::Concern

included do
after_update :touch_alchemy_ingredients
after_touch :touch_alchemy_ingredients
end

private

def touch_alchemy_ingredients
alchemy_ingredients.each(&:touch)
end
end
end
end
18 changes: 0 additions & 18 deletions app/models/alchemy_solidus/touch_alchemy_ingredients.rb

This file was deleted.

0 comments on commit 4146f1c

Please sign in to comment.