I think DI is a nice way to go. Combined with some constants in an
initializer.
class PurchaseProduct
def buy_it_now
acme = acme_provider.new(subscriber)
result = acme.pay_money
end
def acme_provider
@acme_provider ||= ACME_PROVIDER
end
def acme_provider=(obj)
@acme_provider = obj
end
end
if Rails.env.development?
ACME_PROVIDER = FakeAcme
else
ACME_PROVIDER = Acme
end
It is also very easy to swap the dependency in the test:
pp = PurchaseProduct.new
pp.acme_provider = FakeAcme
Sebastian
Steve Hoeksema wrote:
class PurchaseProduct(acme_provider)
def buy_it_now
acme = acme_provider.new(subscriber)
result = acme.pay_money
end
end
--
You received this message because you are subscribed to the Google Groups "Ruby or
Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rails-oceania?hl=en.