English 中文(简体)
如何重构包含大量后附法的铁路模型?
原标题:How to refactor a Rails model that contains significant amount of back-end code?

I have a Rails 2.X model with 421 lines of code/comments that does a significant amount of work on the backend (opening HTTP Get requests, parsing RSS, parsing HTML, etc.). At the same time, I m moving to Resque in order to more quickly get through this backend code. I m wondering what the best way to refactor this would be. Should I move this back-end code to a library that I include in the model? A module? A gem?

Your thoughts would be much appreciated.

我基本上对每个数据项目一米处理有单独的核心任务。 i.e. 分配RSS的饲料,配对一个吉大港定居地,管理该地的管理机构,以及其他一些任务和权利,即目前拥有500项或该模式中的代码线;尽管该模式的大部分内容是通过由戒严操作的背后方文字确定的。

因此,使之更具有活力,更便于转播;即考虑为每组转播单课,并在那里采用静态方法。

然后,如果你愿意的话,我可以要求背信封的管制人打上这些班子。 这种做法是否有意义?

问题回答

从可检测性和思想过程的角度来看,你最好能将这些各种关切分解成自己的(非ARec)模式。 根据你的第一段,你可能拥有RsParser、HtmlParser、服务查询等。

视这一障碍的利用情况(多项目)而定,让你们自己喜欢并使用。

我以前曾撰写过大型和小型转播班,如果你使转播班的频率尽可能小,你就会避免许多痛苦。

The model in question is doing many things.

在结构良好的应用中,每一类都做了一番事情,做得很好。 结构良好的应用的这种特征是它高度可检测的一部分。

你们应当把模式中的许多内容分成多个自成一体的班级,使两者之间的附属关系最小。 然后,你将能够很容易地测试这些新班级,而且你将有一些新的ub点来测试整个模式。

根据我的经验,如果在不止一项申请中使用该守则,也许值得考虑。 否则,通过将《守则》移至“灰.”来增加间接等级似乎产生了许多好处。 事实上,根据你的部署情况,它有可能减缓发展速度。

至于如何重新确定模型,参照所有模型代码,并作为“这一模式如何发挥作用”的问题。 如果你以抽签或计票结束,那么你或许应当努力使每个项目按本类别或按本类别划分(见)。 以这种方式打破责任,使个人的关切更容易撰写针对个人的测试。 特别是在发出外部吉大港山区电话时。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签