build-files 0.2.9 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.simplecov +9 -0
- data/.travis.yml +1 -0
- data/Gemfile +8 -0
- data/README.md +1 -0
- data/Rakefile +3 -1
- data/lib/build/files/monitor.rb +43 -10
- data/lib/build/files/path/filesystem.rb +8 -0
- data/lib/build/files/path.rb +1 -1
- data/lib/build/files/version.rb +1 -1
- data/spec/build/files/monitor_spec.rb +74 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 227bf51c9e640d29bb54d2e1157d7e94e95cae97
|
4
|
+
data.tar.gz: e28a478dccda6e6778aee63e9844c99031daf442
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1b0cb776f992a16b9144eb568412b46dc53af59d59971b3a2e05eb0a6943b0129c290889c19cb075fa53b0707a72967ee2694a6d77e146bfeb1d5c091b40395
|
7
|
+
data.tar.gz: 51b6359b5e1e685b20d3193eafac6607b4cc2c490d5324fee3efbad21b2fb1ac0541f38aded40a2fa76f312aec8754c58c466db314cde8a34e1d42cd77f3fc48
|
data/.simplecov
ADDED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,7 @@ Build::Files is a set of idiomatic classes for dealing with paths and monitoring
|
|
4
4
|
|
5
5
|
[![Build Status](https://secure.travis-ci.org/ioquatix/build-files.png)](http://travis-ci.org/ioquatix/build-files)
|
6
6
|
[![Code Climate](https://codeclimate.com/github/ioquatix/build-files.png)](https://codeclimate.com/github/ioquatix/build-files)
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/ioquatix/build-files/badge.svg)](https://coveralls.io/r/ioquatix/build-files)
|
7
8
|
|
8
9
|
## Installation
|
9
10
|
|
data/Rakefile
CHANGED
data/lib/build/files/monitor.rb
CHANGED
@@ -82,28 +82,61 @@ module Build
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def run(options = {}, &block)
|
85
|
-
|
85
|
+
default_driver = case RUBY_PLATFORM
|
86
|
+
when /linux/i; :inotify
|
87
|
+
when /darwin/i; :fsevent
|
88
|
+
else; :polling
|
89
|
+
end
|
90
|
+
|
91
|
+
if driver = options.fetch(:driver, default_driver)
|
92
|
+
method_name = "run_with_#{driver}"
|
93
|
+
Files.send(method_name, self, options, &block)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.run_with_inotify(monitor, options = {}, &block)
|
99
|
+
require 'rb-inotify'
|
100
|
+
|
101
|
+
notifier = INotify::Notifier.new
|
102
|
+
|
103
|
+
catch(:interrupt) do
|
104
|
+
while true
|
105
|
+
monitor.roots.each do |root|
|
106
|
+
notifier.watch root, :create, :modify, :delete do |event|
|
107
|
+
monitor.update([root])
|
108
|
+
|
109
|
+
yield
|
110
|
+
|
111
|
+
if monitor.updated
|
112
|
+
notifier.stop
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
notifier.run
|
118
|
+
end
|
86
119
|
end
|
87
120
|
end
|
88
121
|
|
89
122
|
def self.run_with_fsevent(monitor, options = {}, &block)
|
90
123
|
require 'rb-fsevent'
|
91
124
|
|
92
|
-
|
125
|
+
notifier = FSEvent.new
|
93
126
|
|
94
127
|
catch(:interrupt) do
|
95
128
|
while true
|
96
|
-
|
129
|
+
notifier.watch monitor.roots do |directories|
|
97
130
|
monitor.update(directories)
|
98
|
-
|
131
|
+
|
99
132
|
yield
|
100
|
-
|
133
|
+
|
101
134
|
if monitor.updated
|
102
|
-
|
135
|
+
notifier.stop
|
103
136
|
end
|
104
137
|
end
|
105
138
|
|
106
|
-
|
139
|
+
notifier.run
|
107
140
|
end
|
108
141
|
end
|
109
142
|
end
|
@@ -112,10 +145,10 @@ module Build
|
|
112
145
|
catch(:interrupt) do
|
113
146
|
while true
|
114
147
|
monitor.update(monitor.roots)
|
115
|
-
|
148
|
+
|
116
149
|
yield
|
117
|
-
|
118
|
-
sleep(options[:latency] ||
|
150
|
+
|
151
|
+
sleep(options[:latency] || 1.0)
|
119
152
|
end
|
120
153
|
end
|
121
154
|
end
|
@@ -39,6 +39,10 @@ module Build
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
+
def touch
|
43
|
+
FileUtils.touch self
|
44
|
+
end
|
45
|
+
|
42
46
|
def exist?
|
43
47
|
File.exist? self
|
44
48
|
end
|
@@ -54,6 +58,10 @@ module Build
|
|
54
58
|
def mkpath
|
55
59
|
FileUtils.mkpath self
|
56
60
|
end
|
61
|
+
|
62
|
+
def rmpath
|
63
|
+
FileUtils.rm_rf self
|
64
|
+
end
|
57
65
|
end
|
58
66
|
end
|
59
67
|
end
|
data/lib/build/files/path.rb
CHANGED
@@ -42,7 +42,7 @@ module Build
|
|
42
42
|
root_components = Path.components(root)
|
43
43
|
|
44
44
|
# Find the common prefix:
|
45
|
-
i = prefix_length(path_components, root_components)
|
45
|
+
i = prefix_length(path_components, root_components) || 0
|
46
46
|
|
47
47
|
# The difference between the root path and the required path, taking into account the common prefix:
|
48
48
|
up = root_components.size - i
|
data/lib/build/files/version.rb
CHANGED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
# Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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.
|
22
|
+
|
23
|
+
require 'build/files/monitor'
|
24
|
+
require 'build/files/path'
|
25
|
+
require 'build/files/path/filesystem'
|
26
|
+
require 'build/files/directory'
|
27
|
+
|
28
|
+
module Build::Files::MonitorSpec
|
29
|
+
include Build::Files
|
30
|
+
|
31
|
+
ROOT = File.expand_path('../tmp', __FILE__)
|
32
|
+
|
33
|
+
describe Build::Files::Monitor do
|
34
|
+
let(:path) {Path.new(ROOT) + "test.txt"}
|
35
|
+
|
36
|
+
before(:all) do
|
37
|
+
Path.new(ROOT).mkpath
|
38
|
+
end
|
39
|
+
|
40
|
+
after(:all) do
|
41
|
+
Path.new(ROOT).rmpath
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should detect additions' do
|
45
|
+
directory = Build::Files::Directory.new(ROOT)
|
46
|
+
monitor = Build::Files::Monitor.new
|
47
|
+
|
48
|
+
changed = false
|
49
|
+
|
50
|
+
monitor.track_changes(directory) do |state|
|
51
|
+
changed = state.added.include? path
|
52
|
+
end
|
53
|
+
|
54
|
+
thread = Thread.new do
|
55
|
+
sleep 1.0
|
56
|
+
|
57
|
+
path.touch
|
58
|
+
end
|
59
|
+
|
60
|
+
triggered = 0
|
61
|
+
|
62
|
+
monitor.run do
|
63
|
+
triggered += 1
|
64
|
+
|
65
|
+
throw :interrupt
|
66
|
+
end
|
67
|
+
|
68
|
+
thread.join
|
69
|
+
|
70
|
+
expect(changed).to be true
|
71
|
+
expect(triggered).to be == 1
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: build-files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -59,6 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".simplecov"
|
62
63
|
- ".travis.yml"
|
63
64
|
- Gemfile
|
64
65
|
- README.md
|
@@ -76,6 +77,7 @@ files:
|
|
76
77
|
- spec/build/files/directory_spec.rb
|
77
78
|
- spec/build/files/glob_spec.rb
|
78
79
|
- spec/build/files/list_spec.rb
|
80
|
+
- spec/build/files/monitor_spec.rb
|
79
81
|
- spec/build/files/path_spec.rb
|
80
82
|
- spec/build/files/state_spec.rb
|
81
83
|
homepage: ''
|
@@ -107,5 +109,6 @@ test_files:
|
|
107
109
|
- spec/build/files/directory_spec.rb
|
108
110
|
- spec/build/files/glob_spec.rb
|
109
111
|
- spec/build/files/list_spec.rb
|
112
|
+
- spec/build/files/monitor_spec.rb
|
110
113
|
- spec/build/files/path_spec.rb
|
111
114
|
- spec/build/files/state_spec.rb
|