-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new NestedClassSet for configuring calculators
We have several actions, and several calculators. Not all calculators work for all actions (e.g. the DistributedAmountCalculator really only works for the AdjustLineItem action, and the `Tiered` ones don't work for `AdjustLineItemQuantityGroups`. Rather than creating a new configuration option for each calculator, let's use something like a Hash here.
Showing
8 changed files
with
52 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spree/core/class_constantizer" | ||
|
||
module SolidusFriendlyPromotions | ||
class NestedClassSet | ||
attr_reader :klass_sets | ||
|
||
def initialize(hash = {}) | ||
@klass_sets = hash.map do |key, value| | ||
[ | ||
key, | ||
Spree::Core::ClassConstantizer::Set.new.tap do |set| | ||
value.each { |klass_name| set << klass_name } | ||
end | ||
] | ||
end.to_h | ||
end | ||
|
||
def [](klass) | ||
klass_sets[klass.name] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters