Rails 2.3+Rake:rake 任务中使用的类的猴子补丁方法

发布于 2024-11-06 18:06:45 字数 189 浏览 8 评论 0原文

如何猴子修补 rake 任务中使用的类的方法?特别是我想重新定义 asset:packager 插件的方法 Synthesis::AssetPackage#compress_js 。我尝试将重新定义放在 RAILS_ROOTRakefile 中,但这不起作用。我不想直接更改插件。

How do you monkey patch a method of a class that is used in a rake task? In particular I want to redefine the method Synthesis::AssetPackage#compress_js of the asset:packager plugin. I tried to place the redefinition in the Rakefile in RAILS_ROOT, but that didn't work. I'd rather not change the plugin directly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏佲洛 2024-11-13 18:06:45

您必须在加载 Synthesis 后重新定义它。我猜你的应用程序的 rake 任务 (Rails.root/lib/tasks/*.rake) 在所有插件之后加载,因此你可以尝试将猴子补丁移到那里。

一般来说,无论如何,您都不应该直接修改 Rails 应用程序的 Rakefile;将任何自定义 rake 任务或其他自定义项放入 lib/tasks/*.rake 中。

You have to redefine it after Synthesis gets loaded. I would guess that your app's rake tasks (Rails.root/lib/tasks/*.rake) get loaded after all the plugins, so you could try moving your monkey-patch into there.

In general, you shouldn't modify a Rails app's Rakefile directly anyway; put any custom rake tasks or other customizations into lib/tasks/*.rake.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文