Created
March 27, 2012 21:19
-
-
Save markburns/2220349 to your computer and use it in GitHub Desktop.
DCI and abstracting persistence
This file contains hidden or 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
shop = Fabricate(:shop, business_hours: shop_hours) | |
shop_factory = Fabricate(:shop_factory) | |
def shop_factory.get id | |
Fabricate(:shop, id: id) | |
end | |
data_store = Fabricate(:data_store) do | |
shop_fetcher shop_factory | |
carrier_fetcher Fabricate(:carrier_factory, all: [carrier]) | |
end | |
options = {time_range: user_time_range, distance: 10, store_id: 1} | |
context = QuoteGeneratingContext.new options, data_store | |
quotes = context.call |
This file contains hidden or 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
class QuoteGenerationContext | |
attr_reader :data_store | |
delegate :store_fetcher, :carrier_fetcher, to: :data_store | |
def initialize options, data_store | |
@data_store = data_store | |
@store = store_fetcher.get(options[:store_id]) | |
@carriers = carrier_fetcher.all | |
@carriers.extend QuoteGenerator | |
end | |
#... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment