Skip to content

Instantly share code, notes, and snippets.

@ShopifyEng
Created March 18, 2021 12:43
Show Gist options
  • Save ShopifyEng/992bb9596ffab69f692379e7755864ed to your computer and use it in GitHub Desktop.
Save ShopifyEng/992bb9596ffab69f692379e7755864ed to your computer and use it in GitHub Desktop.
Repository Pattern
# Gem
module PricingEngine
class Engine
#...
# Calculates the price for variants given the buyer context.
#
# @param context [Schema::BuyerContext] the buyer context
#
# @return [Array<PricingEngine::Schema::Price>] An array of prices for the context passed.
def calculate_prices_for_variants(context)
variant_ids = get_variant_ids_from_context(context)
variants = variants_by_id(variant_ids) # needs to talk to datasources.
process(variants)
end
#...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment