ruby - 如何构建一个非常基本的 Guard 示例?

标签 ruby guard

我的目标是用 Guard 构建一个简单的自定义守卫.我的应用程序的 gem 安装和捆绑程序安装正常。我的 Guardfile 包含:

notification :growl

guard 'eyeball' do
  watch %r{^app/(.*)}
  watch %r{^config/(.*)}
  watch %r{^lib/(.*)}
end

好的,接下来,我需要告诉守卫在比赛发生时该怎么做。但我不知道该在哪里做。 (在这种情况下,我想观察我的应用程序的变化并运行一些任意代码。假设没有 guard available for what I want 。我想自己学习如何做。)

当我运行 guard 时,在真正的“失误并查看接下来弹出的错误”样式中,我收到此错误消息:

ERROR: Could not load 'guard/eyeball' or find class Guard::Eyeball
ERROR: cannot load such file -- guard/eyeball
ERROR: Invalid Guardfile, original error is:
undefined method `new' for nil:NilClass
ERROR: No guards found in Guardfile, please add at least one.
Guard uses Growl to send notifications.
Guard is now watching at '/Users/my-user-name/dev/my-project-name'

所以,这提示我需要创建一个 guard/eyeball.rb 文件。或许?但是我怎么能从文档中知道这一点呢?

我已经(多次)阅读了非常详细和有用的 Guard README但还没有找到一个很好的简单示例来向某人展示如何编写自己的守卫的“基础知识”。出乎意料的是,RailsCasts 也没有真正回答我的问题:参见 RailsCast #264 Guard .

我是否忽略了 Guard README 中的某些内容? ?你能帮忙或指出一个很好的例子吗?谢谢!

最佳答案

甜!我刚刚在 Guard wiki 上找到了一个名为 Create a guard 的 Wiki 页面这回答了我的问题。 README 中没有提到它,所以我不得不挖掘它。

关于ruby - 如何构建一个非常基本的 Guard 示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11174175/

相关文章:

mysql - 使用 Ruby 和 MySQL

ruby-on-rails - 如何在 guard for rspec 中运行单个测试?

ruby-on-rails - ruby 编码::未定义转换错误

ruby - 条件 gem 依赖项

ruby - 为什么我不能在 Object 实例的单例类中包含 Kernel

ruby-on-rails-3 - guard 队给 "uninitialized constant Listen::Turnstile (NameError)"错误

ruby-on-rails - 为什么 rspec 不在 Guard/Spork 启动时运行?

ruby-on-rails - Guard、Spork、Rspec 和 Rails 3 的问题

json - 空注入(inject)器错误 : No provider for JwtHelperService

ruby-on-rails - 如何显示当月的条目?