在没有 Rails 的情况下预加载类?
我正在开发一个大项目,我意识到其中几个组件是一组类,我可以将它们转变为服务并从 Rails 中剥离。但现在我已经做到了,我意识到在没有 Spork 的情况下加载类的缓慢并不是 Rails 缓慢的原因,而是 Ruby 缓慢的原因。有没有像 Spork 这样的东西可以在非 Rails 项目中工作?
I am working on a big project, and I realized that several of the components were groups of classes that I could turn into services and strip from Rails. But now that I've done that I realize that the slowness of loading classes without Spork isn't a function of Rails being slow, but a function of Ruby being slow. Is there something like Spork that will work in non Rails projects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Spork 应该适用于任何 ruby 项目,它只需要更多的设置。
假设您使用的是
rspec 2.x
和spork 0.9
,请创建一个spec_helper.rb
,如下所示:中的所有内容Spork.prefork
块只会运行一次(在 spork 启动时),其余部分将在每次测试调用时运行。如果您有很多特定于框架的设置,那么您最好为您的库制作一个 AppFramework。有关示例,请参阅 padrino AppFramework。
Spork should work just fine for any ruby project, it just requires a bit more setup.
Assuming you're using
rspec 2.x
andspork 0.9
, make aspec_helper.rb
that looks something like:Everything in the
Spork.prefork
block will only be run once (at spork startup), the rest will run on every test invocation.If you have lots of framework-specific setup, you'd probably be better off making an AppFramework for your library. See the padrino AppFramework for an example.