Skip to content

Instantly share code, notes, and snippets.

@markburns
Created March 27, 2012 21:19
Show Gist options
  • Save markburns/2220349 to your computer and use it in GitHub Desktop.
Save markburns/2220349 to your computer and use it in GitHub Desktop.
DCI and abstracting persistence
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
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