开发者

What options do I have when extracting business logic from a Rails app?

I want to extract the business logic from the logistic system coded in the backend of a Rails app, as it is becoming more and more complex. I'm pretty sure there are better options than hard-coding lots of ifs, even if embellished through nice OOP.

I would like to know what options do I have for such purpose. A little bit of research led me to Treetop or Rools parser libraries. Are these good options for what I'm looking to do? Is there a pattern/concept that I'm missing here and I can learn coding it myself instead?

I'd love to hear your opinions and recommendations.

Thanks a lot

ps: Oh, and is it really a win to use a new 开发者_JAVA技巧language for business logic instead of just hard-coding it? Because what I can see from the examples in Treetop, is like a DSL on top of Ruby.


I would try to extract the business logic into a gem. Most of it would be just copy/paste with some tweaks here and there.

The big benefit of this approach is that your gem would just focus on your business logic, so it would not deal with representation etc. As long as you test everything with tdd you should be fine.

Best case would be to just require your gem and then call its most important method like:

require 'mygem'
class SomeClass < ActiveRecord::Base
  def important_method arg1, arg2
    MyGem.compute_results arg1, arg2
  end
end

This way your code stays clean and modular, furthermore you could easily use your logic in a different rails app.

This assumes your logic is some hardcore calculations / ruby code. If your business logic are some sql statements leave them in your app.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜