file-tail 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ 2009-08-21 * 1.0.4 * Fixed the threaded tests for Ruby 1.9.
2
+ * Create a gem spec file.
3
+ * Some cleanup.
1
4
  2008-04-07 * 1.0.3 * Danny Colligan <danny.colligan@sendori.com> reported a
2
5
  memory leak in long running scripts using file-tail. I
3
6
  think this might be a ruby related problem, which is
data/{GPL → COPYING} RENAMED
@@ -1,12 +1,12 @@
1
- GNU GENERAL PUBLIC LICENSE
2
- Version 2, June 1991
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
3
 
4
4
  Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
5
  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6
6
  Everyone is permitted to copy and distribute verbatim copies
7
7
  of this license document, but changing it is not allowed.
8
8
 
9
- Preamble
9
+ Preamble
10
10
 
11
11
  The licenses for most software are designed to take away your
12
12
  freedom to share and change it. By contrast, the GNU General Public
@@ -56,7 +56,7 @@ patent must be licensed for everyone's free use or not licensed at all.
56
56
  The precise terms and conditions for copying, distribution and
57
57
  modification follow.
58
58
 
59
- GNU GENERAL PUBLIC LICENSE
59
+ GNU GENERAL PUBLIC LICENSE
60
60
  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
61
 
62
62
  0. This License applies to any program or other work which contains
@@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals
255
255
  of preserving the free status of all derivatives of our free software and
256
256
  of promoting the sharing and reuse of software generally.
257
257
 
258
- NO WARRANTY
258
+ NO WARRANTY
259
259
 
260
260
  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
261
  FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
@@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
277
  PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
278
  POSSIBILITY OF SUCH DAMAGES.
279
279
 
280
- END OF TERMS AND CONDITIONS
280
+ END OF TERMS AND CONDITIONS
281
281
 
282
- How to Apply These Terms to Your New Programs
282
+ How to Apply These Terms to Your New Programs
283
283
 
284
284
  If you develop a new program, and you want it to be of the greatest
285
285
  possible use to the public, the best way to achieve this is to make it
data/Rakefile CHANGED
@@ -1,13 +1,17 @@
1
1
  # vim: set filetype=ruby et sw=2 ts=2:
2
2
 
3
- require 'rake/gempackagetask'
3
+ begin
4
+ require 'rake/gempackagetask'
5
+ rescue LoadError
6
+ end
7
+ require 'rake/clean'
4
8
  require 'rbconfig'
5
-
6
9
  include Config
7
10
 
8
11
  PKG_NAME = 'file-tail'
9
12
  PKG_VERSION = File.read('VERSION').chomp
10
13
  PKG_FILES = FileList["**/*"].exclude(/^(pkg|coverage|doc)/)
14
+ CLEAN.include 'coverage', 'doc'
11
15
 
12
16
  desc "Installing library"
13
17
  task :install do
@@ -29,35 +33,43 @@ task :coverage do
29
33
  system %{rcov -x '\\btests\/' -Ilib tests/test_file-tail.rb}
30
34
  end
31
35
 
32
- desc "Removing generated files"
33
- task :clean do
34
- rm_rf 'doc'
35
- rm_rf 'coverage'
36
- end
37
-
38
- spec = Gem::Specification.new do |s|
39
- s.name = 'file-tail'
40
- s.version = PKG_VERSION
36
+ if defined? Gem
37
+ spec_src =<<GEM
38
+ # -*- encoding: utf-8 -*-
39
+ Gem::Specification.new do |s|
40
+ s.name = '#{PKG_NAME}'
41
+ s.version = '#{PKG_VERSION}'
41
42
  s.summary = "File::Tail for Ruby"
42
43
  s.description = "Library to tail files in Ruby"
43
44
 
44
- s.files = PKG_FILES
45
+ s.files = #{PKG_FILES.to_a.sort.inspect}
45
46
 
46
47
  s.require_path = 'lib'
47
48
 
48
49
  s.has_rdoc = true
49
- s.rdoc_options << '--title' << 'File::Tail' << '--line-numbers'
50
+ s.rdoc_options << '--main' << 'doc-main.txt'
51
+ s.extra_rdoc_files << 'doc-main.txt'
50
52
  s.test_files << 'tests/test_file-tail.rb'
51
53
 
52
54
  s.author = "Florian Frank"
53
55
  s.email = "flori@ping.de"
54
- s.homepage = "http://file-tail.rubyforge.org"
55
- s.rubyforge_project = "file-tail"
56
+ s.homepage = "http://#{PKG_NAME}.rubyforge.org"
57
+ s.rubyforge_project = "#{PKG_NAME}"
56
58
  end
59
+ GEM
57
60
 
58
- Rake::GemPackageTask.new(spec) do |pkg|
59
- pkg.need_tar = true
60
- pkg.package_files += PKG_FILES
61
+ desc 'Create a gemspec file'
62
+ task :gemspec do
63
+ File.open("#{PKG_NAME}.gemspec", 'w') do |f|
64
+ f.puts spec_src
65
+ end
66
+ end
67
+
68
+ spec = eval(spec_src)
69
+ Rake::GemPackageTask.new(spec) do |pkg|
70
+ pkg.need_tar = true
71
+ pkg.package_files += PKG_FILES
72
+ end
61
73
  end
62
74
 
63
75
  desc m = "Writing version information for #{PKG_VERSION}"
@@ -79,4 +91,6 @@ EOT
79
91
  end
80
92
  end
81
93
 
82
- task :release => [ :clean, :version, :package ]
94
+ task :default => [ :version, :gemspec, :test ]
95
+
96
+ task :release => [ :clean, :version, :gemspec, :package ]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.0.4
data/doc-main.txt ADDED
@@ -0,0 +1,54 @@
1
+ == File::Tail - Tailing files in Ruby
2
+
3
+ === Description
4
+
5
+ This is a small ruby library that allows it to "tail" files in Ruby,
6
+ including following a file, that still is growing like the unix command 'tail
7
+ -f' can.
8
+
9
+ === Author
10
+
11
+ Florian Frank mailto:flori@ping.de
12
+
13
+ === License
14
+
15
+ This is free software; you can redistribute it and/or modify it under
16
+ the terms of the GNU General Public License Version 2 as published by
17
+ the Free Software Foundation: http://www.gnu.org/copyleft/gpl.html
18
+
19
+ === Download
20
+
21
+ The latest version of <b>File::Tail</b> (file-tail) can be found at
22
+
23
+ http://rubyforge.org/frs/?group_id=393
24
+
25
+ Online Documentation should be located at
26
+
27
+ http://file-tail.rubyforge.org
28
+
29
+ === Usage
30
+
31
+ File::Tail is a module in the File class. A lightweight class interface for
32
+ logfiles can be seen under File::Tail::Logfile.
33
+
34
+ Direct extension of File objects with File::Tail works like that:
35
+ File.open(filename) do |log|
36
+ log.extend(File::Tail)
37
+ log.interval = 10
38
+ log.backward(10)
39
+ log.tail { |line| puts line }
40
+ end
41
+
42
+ It's also possible to mix File::Tail in your own File classes
43
+ (see also File::Tail::Logfile):
44
+ class MyFile < File
45
+ include File::Tail
46
+ end
47
+ log = MyFile.new("myfile")
48
+ log.interval = 10
49
+ log.backward(10)
50
+ log.tail { |line| print line }
51
+
52
+ The forward/backward method returns self, so it's possible to chain
53
+ methods together like that:
54
+ log.backward(10).tail { |line| puts line }
data/examples/pager.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- # vim: set et sw=2 ts=2:
3
2
  # A poor man's pager... :)
4
3
 
5
4
  require 'file/tail'
data/examples/tail.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- # vim: set et sw=2 ts=2:
3
2
 
4
3
  require 'file/tail'
5
4
 
data/file-tail.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |s|
3
+ s.name = 'file-tail'
4
+ s.version = '1.0.4'
5
+ s.summary = "File::Tail for Ruby"
6
+ s.description = "Library to tail files in Ruby"
7
+
8
+ s.files = ["CHANGES", "COPYING", "README", "Rakefile", "VERSION", "examples", "examples/pager.rb", "examples/tail.rb", "file-tail.gemspec", "install.rb", "lib", "lib/file", "lib/file/tail", "lib/file/tail.rb", "lib/file/tail/version.rb", "make_doc.rb", "tests", "tests/test_file-tail.rb"]
9
+
10
+ s.require_path = 'lib'
11
+
12
+ s.has_rdoc = true
13
+ s.rdoc_options << '--main' << 'doc-main.txt'
14
+ s.extra_rdoc_files << 'doc-main.txt'
15
+ s.test_files << 'tests/test_file-tail.rb'
16
+
17
+ s.author = "Florian Frank"
18
+ s.email = "flori@ping.de"
19
+ s.homepage = "http://file-tail.rubyforge.org"
20
+ s.rubyforge_project = "file-tail"
21
+ end
data/install.rb CHANGED
@@ -19,4 +19,3 @@ cd 'lib' do
19
19
  file = File.join('file', 'tail', 'version.rb')
20
20
  install(file, dest)
21
21
  end
22
- # vim: set et sw=2 ts=2:
data/lib/file/tail.rb CHANGED
@@ -1,61 +1,6 @@
1
1
  require 'file/tail/version'
2
2
 
3
3
  class File
4
- # = File::Tail - Tailing files in Ruby
5
- #
6
- # == Description
7
- #
8
- # This is a small ruby library that allows it to "tail" files in Ruby,
9
- # including following a file, that still is growing like the unix command 'tail
10
- # -f' can.
11
- #
12
- # == Author
13
- #
14
- # Florian Frank mailto:flori@ping.de
15
- #
16
- # == License
17
- #
18
- # This is free software; you can redistribute it and/or modify it under
19
- # the terms of the GNU General Public License Version 2 as published by
20
- # the Free Software Foundation: http://www.gnu.org/copyleft/gpl.html
21
- #
22
- # == Download
23
- #
24
- # The latest version of <b>File::Tail</b> (file-tail) can be found at
25
- #
26
- # http://rubyforge.org/frs/?group_id=393
27
- #
28
- # Online Documentation should be located at
29
- #
30
- # http://file-tail.rubyforge.org
31
- #
32
- # == Usage
33
- #
34
- # File::Tail is a module in the File class. A lightweight class interface for
35
- # logfiles can be seen under File::Tail::Logfile.
36
- #
37
- # Direct extension of File objects with File::Tail works like that:
38
- # File.open(filename) do |log|
39
- # log.extend(File::Tail)
40
- # log.interval = 10
41
- # log.backward(10)
42
- # log.tail { |line| puts line }
43
- # end
44
- #
45
- # It's also possible to mix File::Tail in your own File classes
46
- # (see also File::Tail::Logfile):
47
- # class MyFile < File
48
- # include File::Tail
49
- # end
50
- # log = MyFile.new("myfile")
51
- # log.interval = 10
52
- # log.backward(10)
53
- # log.tail { |line| print line }
54
- #
55
- # The forward/backward method returns self, so it's possible to chain
56
- # methods together like that:
57
- # log.backward(10).tail { |line| puts line }
58
- #
59
4
  module Tail
60
5
  # This is an easy to use Logfile class that includes
61
6
  # the File::Tail module.
@@ -440,4 +385,3 @@ if $0 == __FILE__
440
385
  log.tail { |line| puts line }
441
386
  end
442
387
  end
443
- # vim: set et sw=2 ts=2:
@@ -1,7 +1,7 @@
1
1
  class File
2
2
  module Tail
3
3
  # File::Tail version
4
- VERSION = '1.0.3'
4
+ VERSION = '1.0.4'
5
5
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
6
6
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
7
7
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/make_doc.rb CHANGED
@@ -2,5 +2,4 @@
2
2
 
3
3
  $outdir = 'doc/'
4
4
  puts "Creating documentation in '#$outdir'."
5
- system "rdoc -t File::Tail -m File::Tail -o #$outdir #{Dir['lib/**/*.rb'] * ' '}"
6
- # vim: set et sw=2 ts=2:
5
+ system "rdoc -m doc-main.txt -o #$outdir doc-main.txt #{Dir['lib/**/*.rb'] * ' '}"
@@ -2,8 +2,8 @@
2
2
 
3
3
  base = File.basename(Dir.pwd)
4
4
  if base == 'tests' || base =~ /file-tail/
5
- Dir.chdir('..') if base == 'tests'
6
- $LOAD_PATH.unshift(File.join(Dir.pwd, 'lib'))
5
+ Dir.chdir('..') if base == 'tests'
6
+ $LOAD_PATH.unshift(File.join(Dir.pwd, 'lib'))
7
7
  end
8
8
 
9
9
  require 'test/unit'
@@ -135,148 +135,152 @@ class TC_FileTail < Test::Unit::TestCase
135
135
  def test_tail_withappend
136
136
  @in.backward
137
137
  lines = []
138
- threads = []
139
- threads << Thread.new do
138
+ logger = Thread.new do
140
139
  begin
141
140
  timeout(1) { @in.tail { |l| lines << l } }
142
141
  rescue TimeoutError
143
142
  end
144
143
  end
145
- threads << Thread.new { append(@out, 10) }
146
- threads.collect { |t| t.join }
144
+ appender = Thread.new { append(@out, 10) }
145
+ appender.join
146
+ logger.join
147
147
  assert_equal(10, lines.size)
148
148
  end
149
149
 
150
150
  def test_tail_truncated
151
151
  @in.backward
152
152
  lines = []
153
- threads = []
154
- threads << appender = Thread.new do
155
- Thread.stop
156
- @out.close
157
- File.truncate(@out.path, 0)
158
- @out = File.new(@in.path, "ab")
159
- append(@out, 10)
160
- end
161
- threads << Thread.new do
153
+ logger = Thread.new do
162
154
  begin
163
155
  timeout(1) do
164
156
  @in.tail do |l|
165
157
  lines << l
166
- lines.size == 100 and appender.wakeup
167
158
  end
168
159
  end
169
160
  rescue TimeoutError
170
161
  end
171
162
  end
172
- threads.collect { |t| t.wakeup and t.join }
163
+ appender = Thread.new do
164
+ until logger.stop?
165
+ sleep 0.1
166
+ end
167
+ @out.close
168
+ File.truncate(@out.path, 0)
169
+ @out = File.new(@in.path, "ab")
170
+ append(@out, 10)
171
+ end
172
+ appender.join
173
+ logger.join
173
174
  assert_equal(10, lines.size)
174
175
  end
175
176
 
176
177
  def test_tail_remove
177
- return if File::PATH_SEPARATOR == ';' # Grmpf! Windows...
178
+ return if File::PATH_SEPARATOR == ';' # Grmpf! Windows...
178
179
  @in.backward
179
- reopened = false
180
- @in.after_reopen { |f| reopened = true }
180
+ reopened = false
181
+ @in.after_reopen { |f| reopened = true }
181
182
  lines = []
182
- threads = []
183
- threads << appender = Thread.new do
184
- Thread.stop
185
- @out.close
186
- File.unlink(@out.path)
187
- @out = File.new(@in.path, "wb")
188
- append(@out, 10)
189
- end
190
- threads << Thread.new do
183
+ logger = Thread.new do
191
184
  begin
192
185
  timeout(2) do
193
186
  @in.tail do |l|
194
187
  lines << l
195
- lines.size == 100 and appender.wakeup
196
188
  end
197
189
  end
198
190
  rescue TimeoutError
199
191
  end
200
192
  end
201
- threads.collect { |t| t.wakeup and t.join }
193
+ appender = Thread.new do
194
+ until logger.stop?
195
+ sleep 0.1
196
+ end
197
+ @out.close
198
+ File.unlink(@out.path)
199
+ @out = File.new(@in.path, "wb")
200
+ append(@out, 10)
201
+ end
202
+ appender.join
203
+ logger.join
202
204
  assert_equal(10, lines.size)
203
- assert reopened
205
+ assert reopened
204
206
  end
205
207
 
206
208
  def test_tail_remove2
207
- return if File::PATH_SEPARATOR == ';' # Grmpf! Windows...
209
+ return if File::PATH_SEPARATOR == ';' # Grmpf! Windows...
208
210
  @in.backward
209
- reopened = false
210
- @in.after_reopen { |f| reopened = true }
211
+ reopened = false
212
+ @in.after_reopen { |f| reopened = true }
211
213
  lines = []
212
- threads = []
213
- threads << appender = Thread.new do
214
- Thread.stop
215
- @out.close
216
- File.unlink(@out.path)
217
- @out = File.new(@in.path, "wb")
218
- append(@out, 10)
219
- sleep 1
220
- append(@out, 10)
221
- File.unlink(@out.path)
222
- @out = File.new(@in.path, "wb")
223
- append(@out, 10)
224
- end
225
- threads << Thread.new do
214
+ logger = Thread.new do
226
215
  begin
227
216
  timeout(2) do
228
217
  @in.tail do |l|
229
218
  lines << l
230
- lines.size == 100 and appender.wakeup
231
219
  end
232
220
  end
233
221
  rescue TimeoutError
234
222
  end
235
223
  end
236
- threads.collect { |t| t.wakeup and t.join }
237
- assert_equal(30, lines.size)
238
- assert reopened
239
- end
240
-
241
- def test_tail_remove3
242
- return if File::PATH_SEPARATOR == ';' # Grmpf! Windows...
243
- @in.backward
244
- reopened = false
245
- @in.after_reopen { |f| reopened = true }
246
- lines = []
247
- threads = []
248
- threads << appender = Thread.new do
249
- Thread.stop
224
+ appender = Thread.new do
225
+ until logger.stop?
226
+ sleep 0.1
227
+ end
250
228
  @out.close
251
229
  File.unlink(@out.path)
252
230
  @out = File.new(@in.path, "wb")
253
231
  append(@out, 10)
254
- sleep 1
232
+ sleep 1
255
233
  append(@out, 10)
256
234
  File.unlink(@out.path)
257
235
  @out = File.new(@in.path, "wb")
258
236
  append(@out, 10)
259
237
  end
260
- threads << Thread.new do
238
+ appender.join
239
+ logger.join
240
+ assert_equal(30, lines.size)
241
+ assert reopened
242
+ end
243
+
244
+ def test_tail_remove3
245
+ return if File::PATH_SEPARATOR == ';' # Grmpf! Windows...
246
+ @in.backward
247
+ reopened = false
248
+ @in.after_reopen { |f| reopened = true }
249
+ lines = []
250
+ logger = Thread.new do
261
251
  begin
262
252
  timeout(2) do
263
253
  @in.tail(15) do |l|
264
254
  lines << l
265
- lines.size == 100 and appender.wakeup
266
255
  end
267
256
  end
268
257
  rescue TimeoutError
269
258
  end
270
259
  end
271
- threads.collect { |t| t.wakeup and t.join }
260
+ appender = Thread.new do
261
+ until logger.stop?
262
+ sleep 0.1
263
+ end
264
+ @out.close
265
+ File.unlink(@out.path)
266
+ @out = File.new(@in.path, "wb")
267
+ append(@out, 10)
268
+ sleep 1
269
+ append(@out, 10)
270
+ File.unlink(@out.path)
271
+ @out = File.new(@in.path, "wb")
272
+ append(@out, 10)
273
+ end
274
+ appender.join
275
+ logger.join
272
276
  assert_equal(15, lines.size)
273
- assert reopened
277
+ assert reopened
274
278
  end
275
279
 
276
280
  def teardown
277
281
  @in.close
278
282
  @out.close
279
- File.unlink(@out.path)
283
+ File.unlink(@out.path)
280
284
  end
281
285
 
282
286
  private
@@ -295,4 +299,3 @@ class TC_FileTail < Test::Unit::TestCase
295
299
  file.flush
296
300
  end
297
301
  end
298
- # vim: set noet sw=2 ts=2:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file-tail
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-07 00:00:00 +02:00
12
+ date: 2009-08-21 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -19,33 +19,31 @@ executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files: []
23
-
22
+ extra_rdoc_files:
23
+ - doc-main.txt
24
24
  files:
25
+ - CHANGES
26
+ - COPYING
27
+ - README
28
+ - Rakefile
29
+ - VERSION
30
+ - examples/pager.rb
31
+ - examples/tail.rb
32
+ - file-tail.gemspec
25
33
  - install.rb
26
- - lib
27
- - lib/file
28
- - lib/file/tail
29
- - lib/file/tail/version.rb
30
34
  - lib/file/tail.rb
35
+ - lib/file/tail/version.rb
31
36
  - make_doc.rb
32
- - README
33
- - CHANGES
34
- - VERSION
35
- - tests
36
37
  - tests/test_file-tail.rb
37
- - Rakefile
38
- - GPL
39
- - examples
40
- - examples/tail.rb
41
- - examples/pager.rb
38
+ - doc-main.txt
42
39
  has_rdoc: true
43
40
  homepage: http://file-tail.rubyforge.org
41
+ licenses: []
42
+
44
43
  post_install_message:
45
44
  rdoc_options:
46
- - --title
47
- - File::Tail
48
- - --line-numbers
45
+ - --main
46
+ - doc-main.txt
49
47
  require_paths:
50
48
  - lib
51
49
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -63,9 +61,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
61
  requirements: []
64
62
 
65
63
  rubyforge_project: file-tail
66
- rubygems_version: 1.0.1
64
+ rubygems_version: 1.3.2
67
65
  signing_key:
68
- specification_version: 2
66
+ specification_version: 3
69
67
  summary: File::Tail for Ruby
70
68
  test_files:
71
69
  - tests/test_file-tail.rb