eventmachine-tail 0.5.20110118081348 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,6 +38,8 @@ class EventMachine::FileTail
38
38
  CHUNKSIZE = 65536
39
39
 
40
40
  #MAXSLEEP = 2
41
+
42
+ FORCE_ENCODING = !! (defined? Encoding)
41
43
 
42
44
  # The path of the file being tailed
43
45
  attr_reader :path
@@ -151,7 +153,7 @@ class EventMachine::FileTail
151
153
  # EOF handler is to do nothing.
152
154
  public
153
155
  def eof
154
- puts "EOF"
156
+ @logger.debug { 'EOF' }
155
157
  # do nothing, subclassers should implement this.
156
158
  end # def eof
157
159
 
@@ -159,7 +161,7 @@ class EventMachine::FileTail
159
161
  # modified or otherwise needs to be acted on.
160
162
  private
161
163
  def notify(status)
162
- @logger.warn("notify: #{status} on #{path}")
164
+ @logger.debug { "notify: #{status} on #{path}" }
163
165
  if status == :modified
164
166
  schedule_next_read
165
167
  elsif status == :moved
@@ -179,6 +181,7 @@ class EventMachine::FileTail
179
181
  def open
180
182
  return if @closed
181
183
  @file.close if @file
184
+ return unless File.exists?(@path)
182
185
  begin
183
186
  @logger.debug "Opening file #{@path}"
184
187
  @file = File.open(@path, "r")
@@ -188,7 +191,7 @@ class EventMachine::FileTail
188
191
  end
189
192
 
190
193
  @naptime = 0
191
- puts "EOF"
194
+ @logger.debug { 'EOF' }
192
195
  @position = 0
193
196
  schedule_next_read
194
197
  end # def open
@@ -207,6 +210,7 @@ class EventMachine::FileTail
207
210
  def watch
208
211
  @watch.stop_watching if @watch
209
212
  @symlink_timer.cancel if @symlink_timer
213
+ return unless File.exists?(@path)
210
214
 
211
215
  @logger.debug "Starting watch on #{@path}"
212
216
  callback = proc { |what| notify(what) }
@@ -254,6 +258,7 @@ class EventMachine::FileTail
254
258
  @logger.debug "#{self}: Reading..."
255
259
  begin
256
260
  data = @file.sysread(CHUNKSIZE)
261
+ data.force_encoding(@file.external_encoding) if FORCE_ENCODING
257
262
 
258
263
  # Won't get here if sysread throws EOF
259
264
  @position += data.length
@@ -1,2 +1,5 @@
1
+ $: << File.expand_path('..', __FILE__)
2
+
3
+
1
4
  require 'test_filetail'
2
5
  require 'test_glob'
@@ -208,5 +208,25 @@ class TestFileTail < Test::Unit::TestCase
208
208
  File.delete(f.path)
209
209
  end
210
210
  end # def test_filetail_tracks_renames
211
+
212
+ def test_encoding
213
+ return if RUBY_VERSION < '1.9.0'
214
+ tmp = Tempfile.new("testfiletail")
215
+ data = DATA.clone
216
+ EM.run do
217
+ abort_after_timeout(1)
218
+
219
+ EM::file_tail(tmp.path) do |filetail, line|
220
+ assert_equal(Encoding.default_external, line.encoding,
221
+ "Expected the read data to have the encoding specified in Encoding.default_external (#{Encoding.default_external}, but was #{line.encoding})")
222
+ finish
223
+ end
224
+
225
+ EM.next_tick do
226
+ tmp.puts(data.shift)
227
+ tmp.flush
228
+ end
229
+ end # EM.run
230
+ end # def test_encoding
211
231
  end # class TestFileTail
212
232
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventmachine-tail
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 5
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 5
8
- - 20110118081348
9
- version: 0.5.20110118081348
8
+ - 6
9
+ - 1
10
+ version: 0.6.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Jordan Sissel
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-01-18 00:00:00 -08:00
18
+ date: 2011-02-22 00:00:00 -08:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 3
28
30
  segments:
29
31
  - 0
30
32
  version: "0"
@@ -69,6 +71,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
71
  requirements:
70
72
  - - ">="
71
73
  - !ruby/object:Gem::Version
74
+ hash: 3
72
75
  segments:
73
76
  - 0
74
77
  version: "0"
@@ -77,13 +80,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
80
  requirements:
78
81
  - - ">="
79
82
  - !ruby/object:Gem::Version
83
+ hash: 3
80
84
  segments:
81
85
  - 0
82
86
  version: "0"
83
87
  requirements: []
84
88
 
85
89
  rubyforge_project:
86
- rubygems_version: 1.3.7
90
+ rubygems_version: 1.5.0
87
91
  signing_key:
88
92
  specification_version: 3
89
93
  summary: eventmachine tail - a file tail implementation with glob support