开发者

Ruby alternative to Service Layer

I am writing a Ruby on Rails app. which will use a 3rd party to do a webservice call or a rest call or some sort of call. I am not sold on which 3rd party I am going to use so I want to isolate this in some sort of facade.

If I was doing this in .NET, I would isolate this functionality in a service that I inject into the controller. This means I can easily m开发者_运维百科ock out the service in order to make it testable but in ruby, it is much easier to mock things so I don't think I need this level of indirection and de-coupling that I would need in a static application.

This feels very un-ruby-like and I would like to hear how more experienced ruby developers approach this problem of isolating the code to make it mockable and testable and also give me the option to swap which 3rd party provider I am using.


If it is a RESTful webservice, I would do this in a model that inherits from ActiveResource::Base. It should be relatively easy to mock this out as well for testing purposes.


The ruby-like version of "I would isolate this functionality in a service that I inject into the controller" would be something like "I would write this as a ruby module that I include in my class"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜