让 FSSM gem(文件观察器)在启动时对所有文件执行此操作
我有一个简单的 FSSM(文件系统状态监视器) 脚本设置来监视一些文件并用它们执行一些操作当它们被改变时。工作起来棒极了。
但是,我希望它在启动脚本时处理具有更新处理程序的任何文件。就像现在一样,如果我在启动脚本之前对文件进行编辑,那么在我再次保存文件之前,我的编辑不会被拾取。在一个需要监视数十个文件的项目中,这并不理想。
那么,如何让 FSSM 处理配置为在我的脚本启动时监视的每个文件呢?
我现在拥有的一个片段:
monitor = FSSM::Monitor.new
monitor.path '.' do
glob '**/*.coffee'
update do |base, relative|
coffee base, relative
end
delete do |base, relative|
remove base, relative
end
end
monitor.run
我希望它在启动时运行更新子句,以便在未观看时编辑的任何文件都会立即得到处理。
I have a simple FSSM (File System State Monitor) script setup to watch some files and do some things with them when they are changed. It's woking great.
However, I want it to process any files it has an update handler for when I boot my script. As it is now, if I make edits to files before I start the script then my edits arent picked up until I save the file again. And in a project with dozens of files being watched, that is less than ideal.
So how make FSSM process every file it is configured to watch when my script launches?
A snippet of what I have now:
monitor = FSSM::Monitor.new
monitor.path '.' do
glob '**/*.coffee'
update do |base, relative|
coffee base, relative
end
delete do |base, relative|
remove base, relative
end
end
monitor.run
I'd like it to run the update clause on launch so that any files edited while they were not being watched would get immediately processed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法可能是在每次调用更新子句时更新零字节文件的时间戳,然后在启动时处理比该标记文件更新的任何文件。由于 update 子句需要在两个地方使用,因此将其存储为 lambda。
我对 Ruby 相当陌生,因此可能有更清晰或更惯用的语法,但基本思想应该会照顾到您。
The simplest method would probably be to update the timestamp of a zero-byte file on each call of the update clause, then on launch process any files that are newer than that marker file. Since the update clause will need to be used in two places, store it as lambda.
I'm fairly new to Ruby, so there may be a cleaner or more idiomatic syntax for this, but the basic idea should take care of you.