rust_watcher 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Cargo.lock +202 -0
- data/Cargo.toml +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +12 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/ext/Rakefile +5 -0
- data/lib/rust_watcher.rb +107 -0
- data/lib/rust_watcher/version.rb +3 -0
- data/rust_watcher.gemspec +28 -0
- data/src/lib.rs +48 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 12d7350857ff57532a80ad07e37119bd74ed4c53
|
4
|
+
data.tar.gz: fbad8025ebd98feb7a8c62a7d908b972f30b6130
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d6070f049fb884e2fc7f1268472282319184edfc938a7917f9cf621facf73e2cbdb1f86f93e99beb603d4c66ae21aa86ba73f39761b9261b468fc8fef4171664
|
7
|
+
data.tar.gz: 67898b4730117149c436091a0aadd673a46d134158e3ea2a497a44185860472b2d63f2110228e58ff261e13427c08a85e32c483ab9f5de65a56bbe1230b1a2dd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.3.0
|
5
|
+
before_install:
|
6
|
+
- curl https://sh.rustup.rs -sSf | sh -s -- -y
|
7
|
+
- export PATH="$HOME/.cargo/bin:$PATH"
|
8
|
+
- gem install bundler -v 1.12.5
|
9
|
+
install:
|
10
|
+
- bundle install --jobs=3 --retry=3
|
11
|
+
- bundle exec rake thermite:build
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at dave@daveallie.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Cargo.lock
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
[root]
|
2
|
+
name = "rust_watcher"
|
3
|
+
version = "0.1.0"
|
4
|
+
dependencies = [
|
5
|
+
"notify 2.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
6
|
+
"ruru 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
7
|
+
]
|
8
|
+
|
9
|
+
[[package]]
|
10
|
+
name = "bitflags"
|
11
|
+
version = "0.4.0"
|
12
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
13
|
+
|
14
|
+
[[package]]
|
15
|
+
name = "bytes"
|
16
|
+
version = "0.3.0"
|
17
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
18
|
+
|
19
|
+
[[package]]
|
20
|
+
name = "cfg-if"
|
21
|
+
version = "0.1.0"
|
22
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
23
|
+
|
24
|
+
[[package]]
|
25
|
+
name = "filetime"
|
26
|
+
version = "0.1.10"
|
27
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
28
|
+
dependencies = [
|
29
|
+
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
30
|
+
]
|
31
|
+
|
32
|
+
[[package]]
|
33
|
+
name = "fsevent"
|
34
|
+
version = "0.2.15"
|
35
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
36
|
+
dependencies = [
|
37
|
+
"bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
38
|
+
"fsevent-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
39
|
+
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
40
|
+
]
|
41
|
+
|
42
|
+
[[package]]
|
43
|
+
name = "fsevent-sys"
|
44
|
+
version = "0.1.5"
|
45
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
46
|
+
dependencies = [
|
47
|
+
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
48
|
+
]
|
49
|
+
|
50
|
+
[[package]]
|
51
|
+
name = "inotify"
|
52
|
+
version = "0.2.3"
|
53
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
54
|
+
dependencies = [
|
55
|
+
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
56
|
+
]
|
57
|
+
|
58
|
+
[[package]]
|
59
|
+
name = "kernel32-sys"
|
60
|
+
version = "0.2.2"
|
61
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
62
|
+
dependencies = [
|
63
|
+
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
64
|
+
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
65
|
+
]
|
66
|
+
|
67
|
+
[[package]]
|
68
|
+
name = "libc"
|
69
|
+
version = "0.2.16"
|
70
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
71
|
+
|
72
|
+
[[package]]
|
73
|
+
name = "log"
|
74
|
+
version = "0.3.6"
|
75
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
76
|
+
|
77
|
+
[[package]]
|
78
|
+
name = "mio"
|
79
|
+
version = "0.5.1"
|
80
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
81
|
+
dependencies = [
|
82
|
+
"bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
83
|
+
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
84
|
+
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
85
|
+
"miow 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
86
|
+
"net2 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
87
|
+
"nix 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
88
|
+
"slab 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
89
|
+
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
90
|
+
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
91
|
+
]
|
92
|
+
|
93
|
+
[[package]]
|
94
|
+
name = "miow"
|
95
|
+
version = "0.1.3"
|
96
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
97
|
+
dependencies = [
|
98
|
+
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
99
|
+
"net2 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
100
|
+
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
101
|
+
"ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
102
|
+
]
|
103
|
+
|
104
|
+
[[package]]
|
105
|
+
name = "net2"
|
106
|
+
version = "0.2.26"
|
107
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
108
|
+
dependencies = [
|
109
|
+
"cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
110
|
+
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
111
|
+
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
112
|
+
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
113
|
+
"ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
114
|
+
]
|
115
|
+
|
116
|
+
[[package]]
|
117
|
+
name = "nix"
|
118
|
+
version = "0.5.1"
|
119
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
120
|
+
dependencies = [
|
121
|
+
"bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
122
|
+
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
123
|
+
]
|
124
|
+
|
125
|
+
[[package]]
|
126
|
+
name = "notify"
|
127
|
+
version = "2.6.3"
|
128
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
129
|
+
dependencies = [
|
130
|
+
"bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
131
|
+
"filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
132
|
+
"fsevent 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
133
|
+
"fsevent-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
134
|
+
"inotify 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
135
|
+
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
136
|
+
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
137
|
+
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
138
|
+
"mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
139
|
+
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
140
|
+
"walkdir 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
141
|
+
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
142
|
+
]
|
143
|
+
|
144
|
+
[[package]]
|
145
|
+
name = "ruby-sys"
|
146
|
+
version = "0.2.13"
|
147
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
148
|
+
dependencies = [
|
149
|
+
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
150
|
+
]
|
151
|
+
|
152
|
+
[[package]]
|
153
|
+
name = "ruru"
|
154
|
+
version = "0.8.1"
|
155
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
156
|
+
dependencies = [
|
157
|
+
"ruby-sys 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
158
|
+
]
|
159
|
+
|
160
|
+
[[package]]
|
161
|
+
name = "slab"
|
162
|
+
version = "0.1.3"
|
163
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
164
|
+
|
165
|
+
[[package]]
|
166
|
+
name = "time"
|
167
|
+
version = "0.1.35"
|
168
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
169
|
+
dependencies = [
|
170
|
+
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
171
|
+
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
172
|
+
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
173
|
+
]
|
174
|
+
|
175
|
+
[[package]]
|
176
|
+
name = "walkdir"
|
177
|
+
version = "0.1.8"
|
178
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
179
|
+
dependencies = [
|
180
|
+
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
181
|
+
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
182
|
+
]
|
183
|
+
|
184
|
+
[[package]]
|
185
|
+
name = "winapi"
|
186
|
+
version = "0.2.8"
|
187
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
188
|
+
|
189
|
+
[[package]]
|
190
|
+
name = "winapi-build"
|
191
|
+
version = "0.1.1"
|
192
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
193
|
+
|
194
|
+
[[package]]
|
195
|
+
name = "ws2_32-sys"
|
196
|
+
version = "0.2.1"
|
197
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
198
|
+
dependencies = [
|
199
|
+
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
200
|
+
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
201
|
+
]
|
202
|
+
|
data/Cargo.toml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
[package]
|
2
|
+
|
3
|
+
name = "rust_watcher"
|
4
|
+
version = "0.1.0"
|
5
|
+
authors = ["Dave Allie"]
|
6
|
+
repository = "https://github.com/daveallie/rust_watcher"
|
7
|
+
publish = false
|
8
|
+
|
9
|
+
[package.metadata.thermite]
|
10
|
+
|
11
|
+
github_releases = true
|
12
|
+
|
13
|
+
[lib]
|
14
|
+
|
15
|
+
crate-type = ["dylib"]
|
16
|
+
|
17
|
+
[dependencies]
|
18
|
+
|
19
|
+
ruru = "0.8"
|
20
|
+
notify = "2.6.3"
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Dave Allie
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Rust Watcher
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/daveallie/rust_watcher.svg?branch=master)](https://travis-ci.org/daveallie/rust_watcher)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rust_watcher'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rust_watcher
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/daveallie/rust_watcher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require 'thermite/tasks'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
Thermite::Tasks.new
|
8
|
+
desc 'Run Rust & Ruby testsuites'
|
9
|
+
task test: ['thermite:build', 'thermite:test', 'spec'] do
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => :test
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rust_watcher"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/ext/Rakefile
ADDED
data/lib/rust_watcher.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require "rust_watcher/version"
|
2
|
+
require 'thermite/fiddle'
|
3
|
+
|
4
|
+
class RustWatcher
|
5
|
+
def initialize(path, &block)
|
6
|
+
@path = path
|
7
|
+
@block = block
|
8
|
+
raise 'Block must take exactly two arguments' unless @block.arity == 2
|
9
|
+
end
|
10
|
+
|
11
|
+
def path
|
12
|
+
@path
|
13
|
+
end
|
14
|
+
|
15
|
+
def start_watcher
|
16
|
+
return if watcher_running?
|
17
|
+
|
18
|
+
child_read, parent_write = IO.pipe
|
19
|
+
parent_read, child_write = IO.pipe
|
20
|
+
|
21
|
+
@watcher_pid = fork do
|
22
|
+
begin
|
23
|
+
parent_read.close
|
24
|
+
parent_write.close
|
25
|
+
|
26
|
+
watch_binding(child_read, child_write)
|
27
|
+
ensure
|
28
|
+
child_read.close
|
29
|
+
child_write.close
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
child_read.close
|
34
|
+
child_write.close
|
35
|
+
|
36
|
+
@runner_pid = fork do
|
37
|
+
begin
|
38
|
+
loop do
|
39
|
+
break unless watcher_running?
|
40
|
+
read_pipe = IO.select([parent_read]).first.first
|
41
|
+
|
42
|
+
if read_pipe
|
43
|
+
output = string_presence(read_pipe.gets)
|
44
|
+
if output
|
45
|
+
op, file = output.split('~~~', 2)
|
46
|
+
@block.call(op, file[1..-2])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
ensure
|
51
|
+
parent_read.close
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
parent_read.close
|
56
|
+
@writer = parent_write
|
57
|
+
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
|
61
|
+
def stop_watcher
|
62
|
+
if watcher_running?
|
63
|
+
unless @writer.closed?
|
64
|
+
@writer.write "."
|
65
|
+
@writer.close
|
66
|
+
end
|
67
|
+
Process.kill("TERM", @watcher_pid)
|
68
|
+
end
|
69
|
+
|
70
|
+
if runner_running?
|
71
|
+
Process.kill("TERM", @runner_pid)
|
72
|
+
end
|
73
|
+
|
74
|
+
nil
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
def watcher_running?
|
79
|
+
begin
|
80
|
+
Process.getpgid(@watcher_pid || -1)
|
81
|
+
true
|
82
|
+
rescue Errno::ESRCH
|
83
|
+
false
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def runner_running?
|
88
|
+
begin
|
89
|
+
Process.getpgid(@runner_pid || -1)
|
90
|
+
true
|
91
|
+
rescue Errno::ESRCH
|
92
|
+
false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def string_presence(str)
|
97
|
+
if str
|
98
|
+
stripped = str.strip
|
99
|
+
stripped.length > 0 ? stripped : nil
|
100
|
+
else
|
101
|
+
nil
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
toplevel_dir = File.dirname(File.dirname(__FILE__))
|
107
|
+
Thermite::Fiddle.load_module('init_rust_watcher', cargo_project_path: toplevel_dir, ruby_project_path: toplevel_dir)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rust_watcher/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rust_watcher"
|
8
|
+
spec.version = RustWatcher::VERSION
|
9
|
+
spec.authors = ["Dave Allie"]
|
10
|
+
spec.email = ["dave@daveallie.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby bindings for rsnotify.}
|
13
|
+
spec.description = %q{Ruby bindings for rsnotify, a cross-platform file watching utility written in Rust.}
|
14
|
+
spec.homepage = "https://github.com/daveallie/rust_watcher"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.extensions << 'ext/Rakefile'
|
23
|
+
spec.add_runtime_dependency 'thermite', '~> 0'
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
end
|
data/src/lib.rs
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#[macro_use]
|
2
|
+
extern crate ruru;
|
3
|
+
extern crate notify;
|
4
|
+
|
5
|
+
use ruru::{Class, RString, Object, AnyObject, NilClass};
|
6
|
+
use std::thread;
|
7
|
+
use std::process::exit;
|
8
|
+
use notify::{RecommendedWatcher, Watcher};
|
9
|
+
use std::sync::mpsc::channel;
|
10
|
+
|
11
|
+
fn watch(top_path: String, pipe_in: AnyObject, pipe_out: AnyObject) -> notify::Result<()> {
|
12
|
+
let (tx, rx) = channel();
|
13
|
+
let mut watcher: RecommendedWatcher = try!(Watcher::new(tx));
|
14
|
+
try!(watcher.watch(&top_path));
|
15
|
+
|
16
|
+
thread::spawn(move || {
|
17
|
+
pipe_in.send("readchar", vec![]);
|
18
|
+
exit(0);
|
19
|
+
});
|
20
|
+
|
21
|
+
loop {
|
22
|
+
match rx.recv() {
|
23
|
+
Ok(notify::Event{ path: Some(path),op: Ok(op) }) => {
|
24
|
+
pipe_out.send("puts", vec![RString::new(&format!("{:?}~~~{:?}", op, path)).to_any_object()]);
|
25
|
+
},
|
26
|
+
Err(e) => println!("watch error {}", e),
|
27
|
+
_ => ()
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
class!(RustWatcher);
|
33
|
+
methods!(
|
34
|
+
RustWatcher,
|
35
|
+
itself,
|
36
|
+
fn notify_watch(pipe_in: AnyObject, pipe_out: AnyObject) -> NilClass {
|
37
|
+
let path = itself.send("path", vec![]).try_convert_to::<RString>().unwrap().to_string();
|
38
|
+
let _ = watch(path, pipe_in.unwrap(), pipe_out.unwrap());
|
39
|
+
NilClass::new()
|
40
|
+
}
|
41
|
+
);
|
42
|
+
|
43
|
+
#[no_mangle]
|
44
|
+
pub extern fn init_rust_watcher() {
|
45
|
+
Class::from_existing("RustWatcher").define(|itself| {
|
46
|
+
itself.def("watch_binding", notify_watch);
|
47
|
+
});
|
48
|
+
}
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rust_watcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Allie
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thermite
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Ruby bindings for rsnotify, a cross-platform file watching utility written
|
70
|
+
in Rust.
|
71
|
+
email:
|
72
|
+
- dave@daveallie.com
|
73
|
+
executables: []
|
74
|
+
extensions:
|
75
|
+
- ext/Rakefile
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
81
|
+
- CODE_OF_CONDUCT.md
|
82
|
+
- Cargo.lock
|
83
|
+
- Cargo.toml
|
84
|
+
- Gemfile
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- bin/console
|
89
|
+
- bin/setup
|
90
|
+
- ext/Rakefile
|
91
|
+
- lib/rust_watcher.rb
|
92
|
+
- lib/rust_watcher/version.rb
|
93
|
+
- rust_watcher.gemspec
|
94
|
+
- src/lib.rs
|
95
|
+
homepage: https://github.com/daveallie/rust_watcher
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.5.1
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Ruby bindings for rsnotify.
|
119
|
+
test_files: []
|