我想写一个lister(
ruby模块)来识别文件夹中的文件创建.我的方案如下
>我有一个名为(文件)的文件夹
>我有一个rails项目,它将在里面创建一个文件(demo.txt)
文件夹(‘文件’)
>我需要编写一个监听器来识别文件更改并启动
读取文件(demo.txt)
我不知道从哪里开始创建这个ruby模块.请任何人帮助我指导我走正确的道路.
这是我使用的ruby版本’ruby 1.8.7(2010-06-23 patchlevel 299)[i686-linux]’
提前致谢
干杯
sameera
有一些小型库,您可以利用,学习或构建,例如,
> https://github.com/mynyml/watchr
Agile development tool that monitors a directory tree,and triggers a user defined action whenever an observed file is modified. Its most typical use is continuous testing,and as such it is a more flexible alternative to autotest.
> http://codeforpeople.rubyforge.org/directory_watcher/
The directory watcher operates by scanning a directory at some interval and generating a list of files based on a user supplied glob pattern. As the file list changes from one interval to the next,events are generated and dispatched to registered observers. Three types of events are supported — added,modified,and removed.
> https://github.com/guard/guard
Guard is a command line tool to easily handle events on files modifications (FSEvent / Inotify / Polling support).
> http://rubydoc.info/gems/rb-inotify/0.8.6/frames
This is a simple wrapper over the inotify Linux kernel subsystem for monitoring changes to files and directories. It uses the FFI gem to avoid having to compile a C extension.