加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在ruby中编写文件更改侦听器

发布时间:2020-12-17 03:27:52 所属栏目:百科 来源:网络整理
导读:我想写一个lister( ruby模块)来识别文件夹中的文件创建.我的方案如下 我有一个名为(文件)的文件夹 我有一个rails项目,它将在里面创建一个文件(demo.txt) 文件夹(‘文件’) 我需要编写一个监听器来识别文件更改并启动 读取文件(demo.txt) 我不知道从哪里开始
我想写一个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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读