autoreload 0.3.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/.ruby +31 -26
- data/.yardopts +5 -0
- data/Assembly +40 -0
- data/COPYING.rdoc +371 -12
- data/HISTORY.rdoc +40 -0
- data/MANIFEST +14 -0
- data/PROFILE +28 -0
- data/README.rdoc +31 -17
- data/Rakefile +9 -0
- data/VERSION +1 -0
- data/autoreload.gemspec +143 -0
- data/lib/autoreload.rb +3 -2
- data/lib/autoreload/reloader.rb +46 -33
- data/lib/autoreload/version.rb +1 -1
- data/site/assets/icon.png +0 -0
- data/site/assets/screen.css +149 -0
- data/site/index.html +135 -0
- data/site/index.page +80 -0
- data/site/template.layout +77 -0
- data/spec/autoreload_spec.rb +8 -29
- data/spec/helper.rb +29 -0
- data/spec/require_spec.rb +37 -0
- data/try/changeme.rb +5 -0
- data/try/start.rb +20 -0
- data/work/autoreload.rb +115 -0
- data/work/consider/autoreload.rb +115 -0
- data/work/deprecated/Changes.txt +56 -0
- data/work/deprecated/Rakefile +80 -0
- data/work/deprecated/default_task.rb +129 -0
- data/work/deprecated/lookup.rb +174 -0
- data/work/deprecated/meta/authors +2 -0
- data/work/deprecated/meta/description +3 -0
- data/work/deprecated/meta/name +1 -0
- data/work/deprecated/meta/summary +1 -0
- data/work/deprecated/meta/version +1 -0
- data/work/deprecated/scripts/lib-txt2html.rb +133 -0
- data/work/deprecated/scripts/makemanifest.rb +20 -0
- data/work/deprecated/scripts/txt2html +10 -0
- data/work/deprecated/setup.rb +1585 -0
- metadata +59 -30
- data/GPL3.txt +0 -674
- data/lib/autoreload/lookup.rb +0 -91
data/spec/autoreload_spec.rb
CHANGED
@@ -1,43 +1,22 @@
|
|
1
|
-
require '
|
2
|
-
require 'pathname'
|
3
|
-
require 'autoreload'
|
4
|
-
|
5
|
-
class Pathname
|
6
|
-
def write(str)
|
7
|
-
self.open('wb') {|out|
|
8
|
-
out.print str
|
9
|
-
}
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module AutoReload
|
14
|
-
class Reloader
|
15
|
-
public :warn
|
16
|
-
end
|
17
|
-
end
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
18
2
|
|
19
3
|
describe "AutoReload" do
|
20
4
|
|
21
|
-
before :all do
|
22
|
-
FileUtils.mkdir('tmp') unless File.exist?('tmp')
|
23
|
-
end
|
24
|
-
|
25
5
|
it "should autoreload" do
|
26
6
|
# create a library
|
27
7
|
library = Pathname.new('tmp/library.rb')
|
28
8
|
library.write 'def foo; 1; end'
|
29
9
|
|
30
10
|
# setup the autoreload
|
31
|
-
autoreload(
|
32
|
-
|
33
|
-
|
34
|
-
require "#{library}"
|
11
|
+
autoreload(:interval => 1) do #, :verbose=>true)
|
12
|
+
require "library"
|
13
|
+
end
|
35
14
|
|
36
15
|
# check the number
|
37
|
-
foo.
|
16
|
+
foo.must_equal 1
|
38
17
|
|
39
18
|
# wait is needed for time stamp to not be same with the next file.
|
40
|
-
sleep
|
19
|
+
sleep 2
|
41
20
|
|
42
21
|
# recreate the file
|
43
22
|
library.write 'def foo; 2; end'
|
@@ -46,10 +25,10 @@ describe "AutoReload" do
|
|
46
25
|
sleep 2
|
47
26
|
|
48
27
|
# check the number again
|
49
|
-
foo.
|
28
|
+
foo.must_equal 2
|
50
29
|
|
51
30
|
# clean up
|
52
|
-
library.
|
31
|
+
library.delete
|
53
32
|
end
|
54
33
|
|
55
34
|
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
require 'pathname'
|
6
|
+
require 'autoreload'
|
7
|
+
|
8
|
+
# Some helper stuff....
|
9
|
+
|
10
|
+
# create a tmp directory
|
11
|
+
FileUtils.mkdir('tmp') unless File.exist?('tmp')
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift 'lib'
|
14
|
+
$LOAD_PATH.unshift 'tmp'
|
15
|
+
|
16
|
+
class Pathname
|
17
|
+
def write(str)
|
18
|
+
self.open('w') {|out|
|
19
|
+
out.puts str
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module AutoReload
|
25
|
+
class Reloader
|
26
|
+
public :warn
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
|
3
|
+
describe "AutoReload" do
|
4
|
+
|
5
|
+
it "should autoreload a require of a require" do
|
6
|
+
library1 = Pathname.new('tmp/library1.rb')
|
7
|
+
library2 = Pathname.new('tmp/library2.rb')
|
8
|
+
|
9
|
+
library1.write "require 'library2'"
|
10
|
+
library2.write "def foo; 1; end"
|
11
|
+
|
12
|
+
# setup the autoreload
|
13
|
+
autoreload(:interval => 1) do #, :verbose=>true)
|
14
|
+
require "library1"
|
15
|
+
end
|
16
|
+
|
17
|
+
# check the number
|
18
|
+
foo.must_equal 1
|
19
|
+
|
20
|
+
# wait is needed for time stamp to not be same with the next file.
|
21
|
+
sleep 2
|
22
|
+
|
23
|
+
# recreate the file
|
24
|
+
library2.write "def foo; 2; end"
|
25
|
+
|
26
|
+
# wait again for the autoreload loop to repeat.
|
27
|
+
sleep 2
|
28
|
+
|
29
|
+
# check the number again
|
30
|
+
foo.must_equal 2
|
31
|
+
|
32
|
+
# clean up
|
33
|
+
library2.delete
|
34
|
+
library1.delete
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/try/changeme.rb
ADDED
data/try/start.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# sample1.rb
|
2
|
+
|
3
|
+
# Run this script and change 'foo.rb' while this script is running.
|
4
|
+
|
5
|
+
__dir__ = File.dirname(__FILE__)
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.join(__dir__, '../lib'))
|
8
|
+
|
9
|
+
library = './' + __dir__ + '/changeme.rb'
|
10
|
+
|
11
|
+
require 'autoreload'
|
12
|
+
|
13
|
+
autoreload(:interval=>1, :verbose=>true)
|
14
|
+
require library
|
15
|
+
end
|
16
|
+
|
17
|
+
loop {
|
18
|
+
puts message
|
19
|
+
sleep 1
|
20
|
+
}
|
data/work/autoreload.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
module Kernel
|
2
|
+
|
3
|
+
# Autoreload feature files.
|
4
|
+
#
|
5
|
+
# Automatically reload, at regular intervals, any previously loaded features,
|
6
|
+
# and/or other files not already loaded, if they have been modified since the last
|
7
|
+
# interval check. A numeric parameter sets the reload interval in seconds
|
8
|
+
# and the file parameter can either be a glob string or an array
|
9
|
+
# of file paths. If a glob string, it is expanded only once on the initial
|
10
|
+
# method call. Supplying a boolean parameter of 'false' will force autreload to
|
11
|
+
# skip previously loaded features and only reload the specified files.
|
12
|
+
# Also keeps a "dirty" flag.
|
13
|
+
#
|
14
|
+
# Copyright (c) 2003 Michael Neumann
|
15
|
+
|
16
|
+
def autoreload( *args )
|
17
|
+
|
18
|
+
check_interval=10
|
19
|
+
include_features = true
|
20
|
+
files = nil
|
21
|
+
|
22
|
+
args.each do |arg|
|
23
|
+
case arg
|
24
|
+
when Numeric
|
25
|
+
check_interval = arg
|
26
|
+
when String
|
27
|
+
files = Dir.glob( arg )
|
28
|
+
when Array
|
29
|
+
files = arg
|
30
|
+
when TrueClass, FalseClass
|
31
|
+
include_features = arg
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
file_mtime = {}
|
36
|
+
|
37
|
+
Thread.new(Time.now) do |start_time|
|
38
|
+
loop do
|
39
|
+
sleep check_interval
|
40
|
+
|
41
|
+
if include_features
|
42
|
+
feature_files = $LOADED_FEATURES.collect { |feature|
|
43
|
+
$LOAD_PATH.each { |lp| file = File.join(lp, feature) }
|
44
|
+
}.flatten
|
45
|
+
|
46
|
+
feature_files.each { |file|
|
47
|
+
if File.exists?(file) and (mtime = File.stat(file).mtime) > (file_mtime[file] || start_time)
|
48
|
+
$autoreload_dirty = true
|
49
|
+
file_mtime[file] = mtime
|
50
|
+
STDERR.puts "File '#{ file }' reloaded"
|
51
|
+
begin
|
52
|
+
load(file)
|
53
|
+
rescue Exception => e
|
54
|
+
STDERR.puts e.inspect
|
55
|
+
end
|
56
|
+
end
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
if files
|
61
|
+
files.each do |file|
|
62
|
+
if File.exists?(file) and (mtime = File.stat(file).mtime) > (file_mtime[file] || start_time)
|
63
|
+
$autoreload_dirty = true
|
64
|
+
file_mtime[file] = mtime
|
65
|
+
STDERR.puts "File '#{ file }' changed"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
# Same as #autoreload, but does not include previously loaded features.
|
76
|
+
# This is equivalent to as adding a 'false' parameter to #autoreload.
|
77
|
+
#
|
78
|
+
def autoreload_files(*args)
|
79
|
+
autoreload(false, *args)
|
80
|
+
end
|
81
|
+
|
82
|
+
# deprecated
|
83
|
+
#def autoreload_glob(*args)
|
84
|
+
# warn "autoreload_glob will be deprecated. Use autoreload_files instead."
|
85
|
+
# autoreload_files(*args)
|
86
|
+
#end
|
87
|
+
end
|
88
|
+
|
89
|
+
#--
|
90
|
+
# # OLD VERSION
|
91
|
+
# def autoreload(check_interval=10)
|
92
|
+
# Thread.new(Time.now) { |start_time|
|
93
|
+
# file_mtime = {}
|
94
|
+
# loop {
|
95
|
+
# sleep check_interval
|
96
|
+
# $LOADED_FEATURES.each { |feature|
|
97
|
+
# $LOAD_PATH.each { |lp|
|
98
|
+
# file = File.join(lp, feature)
|
99
|
+
# if (File.exists?(file) and
|
100
|
+
# File.stat(file).mtime > (file_mtime[file] || start_time))
|
101
|
+
# file_mtime[file] = File.stat(file).mtime
|
102
|
+
# STDERR.puts "reload #{ file }"
|
103
|
+
# begin
|
104
|
+
# load(file)
|
105
|
+
# rescue Exception => e
|
106
|
+
# STDERR.puts e.inspect
|
107
|
+
# end
|
108
|
+
# end
|
109
|
+
# }
|
110
|
+
# }
|
111
|
+
# }
|
112
|
+
# }
|
113
|
+
# end
|
114
|
+
#++
|
115
|
+
|
@@ -0,0 +1,115 @@
|
|
1
|
+
module Kernel
|
2
|
+
|
3
|
+
# Autoreload feature files.
|
4
|
+
#
|
5
|
+
# Automatically reload, at regular intervals, any previously loaded features,
|
6
|
+
# and/or other files not already loaded, if they have been modified since the last
|
7
|
+
# interval check. A numeric parameter sets the reload interval in seconds
|
8
|
+
# and the file parameter can either be a glob string or an array
|
9
|
+
# of file paths. If a glob string, it is expanded only once on the initial
|
10
|
+
# method call. Supplying a boolean parameter of 'false' will force autreload to
|
11
|
+
# skip previously loaded features and only reload the specified files.
|
12
|
+
# Also keeps a "dirty" flag.
|
13
|
+
#
|
14
|
+
# Copyright (c) 2003 Michael Neumann
|
15
|
+
|
16
|
+
def autoreload( *args )
|
17
|
+
|
18
|
+
check_interval=10
|
19
|
+
include_features = true
|
20
|
+
files = nil
|
21
|
+
|
22
|
+
args.each do |arg|
|
23
|
+
case arg
|
24
|
+
when Numeric
|
25
|
+
check_interval = arg
|
26
|
+
when String
|
27
|
+
files = Dir.glob( arg )
|
28
|
+
when Array
|
29
|
+
files = arg
|
30
|
+
when TrueClass, FalseClass
|
31
|
+
include_features = arg
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
file_mtime = {}
|
36
|
+
|
37
|
+
Thread.new(Time.now) do |start_time|
|
38
|
+
loop do
|
39
|
+
sleep check_interval
|
40
|
+
|
41
|
+
if include_features
|
42
|
+
feature_files = $LOADED_FEATURES.collect { |feature|
|
43
|
+
$LOAD_PATH.each { |lp| file = File.join(lp, feature) }
|
44
|
+
}.flatten
|
45
|
+
|
46
|
+
feature_files.each { |file|
|
47
|
+
if File.exists?(file) and (mtime = File.stat(file).mtime) > (file_mtime[file] || start_time)
|
48
|
+
$autoreload_dirty = true
|
49
|
+
file_mtime[file] = mtime
|
50
|
+
STDERR.puts "File '#{ file }' reloaded"
|
51
|
+
begin
|
52
|
+
load(file)
|
53
|
+
rescue Exception => e
|
54
|
+
STDERR.puts e.inspect
|
55
|
+
end
|
56
|
+
end
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
if files
|
61
|
+
files.each do |file|
|
62
|
+
if File.exists?(file) and (mtime = File.stat(file).mtime) > (file_mtime[file] || start_time)
|
63
|
+
$autoreload_dirty = true
|
64
|
+
file_mtime[file] = mtime
|
65
|
+
STDERR.puts "File '#{ file }' changed"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
# Same as #autoreload, but does not include previously loaded features.
|
76
|
+
# This is equivalent to as adding a 'false' parameter to #autoreload.
|
77
|
+
#
|
78
|
+
def autoreload_files(*args)
|
79
|
+
autoreload(false, *args)
|
80
|
+
end
|
81
|
+
|
82
|
+
# deprecated
|
83
|
+
#def autoreload_glob(*args)
|
84
|
+
# warn "autoreload_glob will be deprecated. Use autoreload_files instead."
|
85
|
+
# autoreload_files(*args)
|
86
|
+
#end
|
87
|
+
end
|
88
|
+
|
89
|
+
#--
|
90
|
+
# # OLD VERSION
|
91
|
+
# def autoreload(check_interval=10)
|
92
|
+
# Thread.new(Time.now) { |start_time|
|
93
|
+
# file_mtime = {}
|
94
|
+
# loop {
|
95
|
+
# sleep check_interval
|
96
|
+
# $LOADED_FEATURES.each { |feature|
|
97
|
+
# $LOAD_PATH.each { |lp|
|
98
|
+
# file = File.join(lp, feature)
|
99
|
+
# if (File.exists?(file) and
|
100
|
+
# File.stat(file).mtime > (file_mtime[file] || start_time))
|
101
|
+
# file_mtime[file] = File.stat(file).mtime
|
102
|
+
# STDERR.puts "reload #{ file }"
|
103
|
+
# begin
|
104
|
+
# load(file)
|
105
|
+
# rescue Exception => e
|
106
|
+
# STDERR.puts e.inspect
|
107
|
+
# end
|
108
|
+
# end
|
109
|
+
# }
|
110
|
+
# }
|
111
|
+
# }
|
112
|
+
# }
|
113
|
+
# end
|
114
|
+
#++
|
115
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
== 2007-07-07
|
2
|
+
|
3
|
+
* lib/autoreload.rb: Do not use @thread.
|
4
|
+
|
5
|
+
== 2007-07-06
|
6
|
+
|
7
|
+
* Rakefile: To use Chages.txt
|
8
|
+
|
9
|
+
== 2007-07-05
|
10
|
+
|
11
|
+
* Changes.txt: New file. Moved from ChangeLog.
|
12
|
+
* ChangeLog: Deleted.
|
13
|
+
|
14
|
+
* bin: Deleted.
|
15
|
+
|
16
|
+
* lib/autoreload.rb: Make it start from class method.
|
17
|
+
|
18
|
+
* lib/autoreload/version.rb: Removed.
|
19
|
+
|
20
|
+
* lib/autoreload.rb: Reformat.
|
21
|
+
|
22
|
+
* examples/sample1.rb: New file.
|
23
|
+
* examples/foo.rb: New file.
|
24
|
+
|
25
|
+
* default_task.rb: New file. Splited from Rakefile.
|
26
|
+
* Rakefile: Follow.
|
27
|
+
* script/lib-txt2html.rb: New file.
|
28
|
+
* script/makemanifest.rb: New file.
|
29
|
+
|
30
|
+
* License.txt: Update license to Ruby license.
|
31
|
+
|
32
|
+
* test/test_autoreload.rb: Sometimes test is failed.
|
33
|
+
|
34
|
+
* default_task.rb: Check file exist in chmod task.
|
35
|
+
|
36
|
+
* default_task.rb: Specify version and download.
|
37
|
+
* scripts/lib-txt2html.rb: Remove dependency.
|
38
|
+
* scripts/txt2html: Follow.
|
39
|
+
|
40
|
+
== 2007-07-04
|
41
|
+
|
42
|
+
* License.txt: created.
|
43
|
+
* README.txt: created.
|
44
|
+
|
45
|
+
* lib/autoreload/version.rb: Truncated.
|
46
|
+
* Rakefile: Ditto.
|
47
|
+
|
48
|
+
* lib/autoreload.rb: Created.
|
49
|
+
* test/test_autoreload.rb: Ditto.
|
50
|
+
|
51
|
+
* lib/autoreload.rb: Refactoring.
|
52
|
+
|
53
|
+
== 2007-07-04
|
54
|
+
|
55
|
+
* Init.
|
56
|
+
|