autoreload 0.2.0 → 0.3.1

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.
@@ -0,0 +1,23 @@
1
+ = RELEASE HISTORY
2
+
3
+
4
+ == 0.3.0 (2010-10-14)
5
+
6
+ * Fix issue with looking up Roller libraries.
7
+ * Switch testing framework to RSpec2.
8
+
9
+
10
+ == 0.2.0 (2010-05-10)
11
+
12
+ * Completely reworked API.
13
+
14
+
15
+ == 0.1.0 (2010-05-01)
16
+
17
+ * Same as original, but now a RubyWorks project.
18
+
19
+
20
+ == 0.0.1 (2007-07-01)
21
+
22
+ * Initial release
23
+
@@ -1,9 +1,5 @@
1
1
  = Autoreload
2
2
 
3
- * home: http://rubyworks.github.com/autoreload
4
- * work: http://github.com/rubyworks/autoreload
5
-
6
-
7
3
  == DESCRIPTION
8
4
 
9
5
  Autoreload automatically reloads library files when they have been
@@ -11,6 +7,12 @@ updated. It is especailly useful when testing stateless services
11
7
  such as web applications.
12
8
 
13
9
 
10
+ == RESOURCES
11
+
12
+ * home: http://rubyworks.github.com/autoreload
13
+ * work: http://github.com/rubyworks/autoreload
14
+
15
+
14
16
  == HOW TO USE
15
17
 
16
18
  Say we have a library <tt>foo.rb</tt> in our load path:
@@ -37,6 +39,9 @@ effect in <tt>example.rb</tt> within two seconds of being made.
37
39
 
38
40
  == COPYRIGHT
39
41
 
40
- Copyright (c) 2007 Kouichirou Eto
42
+ (GPL v3 License)
43
+
44
+ * Copyright (c) 2007 Kouichirou Eto
45
+ * Copyright (c) 2010 Thomas Sawyer
41
46
 
42
- Copyright (c) 2010 Thomas Sawyer
47
+ See COPYING.rdoc for more information.
@@ -1,8 +1,5 @@
1
+ require 'autoreload/version'
1
2
  require 'autoreload/reloader'
2
-
3
- module AutoReload
4
- # TODO: version constant
5
- end
6
3
 
7
4
  def autoreload(*files)
8
5
  AutoReload::Reloader.start(*files)
@@ -34,7 +34,8 @@ module AutoReload
34
34
  plugins = []
35
35
  #directory = options[:directory] || DIRECTORY
36
36
  if defined?(::Roll)
37
- ::Roll::Library.ledger.each do |name, lib|
37
+ # Not ::Roll::Library ?
38
+ ::Library.ledger.each do |name, lib|
38
39
  lib = lib.sort.first if Array===lib
39
40
  lib.loadpath.each do |path|
40
41
  #find = File.join(lib.location, path, directory, match)
@@ -1,140 +1,139 @@
1
1
  require 'thread'
2
- require 'autoreload/lookup'
2
+ require 'autoreload/lookup'
3
3
 
4
4
  module AutoReload
5
-
6
- # Reload class does all the heavy lifting
7
- # for AutoReload library.
5
+
6
+ # Reload class does all the heavy lifting
7
+ # for AutoReload library.
8
8
  #
9
- class Reloader
10
-
9
+ class Reloader
10
+
11
11
  # Shortcut for Reloader.new(*args).start.
12
12
  def self.start(*args)
13
13
  self.new(*args).start
14
14
  end
15
-
15
+
16
16
  # Default interval is one second.
17
17
  DEFAULT_INTERVAL = 1
18
-
19
- # New Reloader.
20
- #
21
- # === Options
22
- #
23
- # :interval - seconds betwee updates
24
- # :verbose - true provides reload warning
25
- # :reprime - include $0 in reload list
18
+
19
+ # New Reloader.
26
20
  #
27
- def initialize(*files)
28
- options = Hash===files.last ? files.pop : {}
21
+ # === Options
22
+ #
23
+ # :interval - seconds betwee updates
24
+ # :verbose - true provides reload warning
25
+ # :reprime - include $0 in reload list
26
+ #
27
+ def initialize(*files)
28
+ options = Hash===files.last ? files.pop : {}
29
+
30
+ @files = files.map{ |file| file.to_s } #Dir.glob(file) }.flatten.compact
29
31
 
30
- @files = files.map{ |file| file.to_s } #Dir.glob(file) }.flatten.compact
31
-
32
32
  @interval = options[:interval] || DEFAULT_INTERVAL
33
- @verbose = options[:verbose]
34
- @reprime = options[:reprime]
35
-
33
+ @verbose = options[:verbose]
34
+ @reprime = options[:reprime]
35
+
36
36
  @status = {}
37
37
  end
38
-
38
+
39
39
  # Start the reload thread.
40
- def start
41
- update # primate the path loads
40
+ def start
41
+ update # primate the path loads
42
42
  @thread = Thread.new do
43
43
  loop do
44
44
  begin
45
45
  update
46
46
  rescue Exception
47
- warn 'update failed: ' + $!
47
+ warn 'update failed: ' + $!
48
48
  end
49
49
  sleep @interval
50
50
  end
51
51
  end
52
52
  @thread.abort_on_exception = true
53
53
  end
54
-
55
- # Kills the autoreload thread.
56
- def stop
57
- @thread.kill if @thread
58
- end
59
-
60
- #
61
- attr :thread
62
-
63
- # List of files provided to autoreload.
64
- attr :files
65
-
66
- # Status hash, used to track reloads.
67
- attr :status
68
-
69
- # The periodic interval of reload.
70
- attr :interval
71
-
72
- # Provide warning on reload.
73
- def verbose?
74
- @verbose || $VERBOSE
75
- end
76
-
77
- # Is $0 in the reload list?
78
- def reprime?
79
- @reprime
80
- end
54
+
55
+ # Kills the autoreload thread.
56
+ def stop
57
+ @thread.kill if @thread
58
+ end
59
+
60
+ #
61
+ attr :thread
62
+
63
+ # List of files provided to autoreload.
64
+ attr :files
65
+
66
+ # Status hash, used to track reloads.
67
+ attr :status
68
+
69
+ # The periodic interval of reload.
70
+ attr :interval
71
+
72
+ # Provide warning on reload.
73
+ def verbose?
74
+ @verbose || $VERBOSE
75
+ end
76
+
77
+ # Is $0 in the reload list?
78
+ def reprime?
79
+ @reprime
80
+ end
81
81
 
82
82
  private
83
-
84
- # List of library files to autoreload.
85
- #--
86
- # ISSUE: Why include $0 ?
83
+
84
+ # List of library files to autoreload.
87
85
  #--
88
- def libraries
89
- if @files.empty?
90
- @reprime ? [$0] + $" : $"
91
- else
92
- @files
93
- end
94
- end
95
-
96
- # Iterate through all selection library files and reload if needed.
97
- def update
86
+ # ISSUE: Why include $0 ?
87
+ #--
88
+ def libraries
89
+ if @files.empty?
90
+ @reprime ? [$0] + $" : $"
91
+ else
92
+ @files
93
+ end
94
+ end
95
+
96
+ # Iterate through all selection library files and reload if needed.
97
+ def update
98
98
  libraries.each{ |lib| check(lib) }
99
99
  end
100
-
100
+
101
101
  # Check status and reload if out-of-date.
102
- def check(lib)
103
- if @status.key?(lib)
102
+ def check(lib)
103
+ if @status.key?(lib)
104
104
  file, mtime = @status[lib]
105
-
106
- return unless file # file never was
107
- return unless FileTest.exist?(file) # file has disappered
108
105
 
109
- curtime = File.mtime(file).to_i
106
+ return unless file # file never was
107
+ return unless FileTest.exist?(file) # file has disappered
108
+
109
+ curtime = File.mtime(file).to_i
110
110
 
111
111
  if mtime < curtime
112
112
  warn "reload: '#{file}'" if verbose?
113
113
  load file
114
114
  @status[lib] = [file, curtime]
115
115
  end
116
- else
117
- @status[lib] = get_status(lib)
116
+ else
117
+ @status[lib] = get_status(lib)
118
118
  end
119
119
  end
120
-
120
+
121
121
  # Get library file status.
122
- def get_status(lib)
122
+ def get_status(lib)
123
123
  file = Lookup.find(lib).first
124
124
  if file #FileTest.exist?(file)
125
- [file, File.mtime(file).to_i]
126
- else
127
- warn "reload fail: library '#{lib}' not found" if verbose?
125
+ [file, File.mtime(file).to_i]
126
+ else
127
+ warn "reload fail: library '#{lib}' not found" if verbose?
128
128
  #raise "The library '#{lib}' is not found."
129
129
  #$stdout.puts(message("The library '#{lib}' is not found.")) if @verbose
130
130
  [nil, nil]
131
131
  end
132
132
  end
133
-
134
- end
133
+
134
+ end
135
135
 
136
136
  end
137
-
137
+
138
138
  # Copyright (C) 2003,2007 Kouichirou Eto
139
- # Copyright (C) 2010 Thomas Sawyer
140
-
139
+ # Copyright (C) 2010 Thomas Sawyer
@@ -0,0 +1,3 @@
1
+ module AutoReload
2
+ VERSION = '0.3.0'
3
+ end
@@ -0,0 +1,55 @@
1
+ require 'fileutils'
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
18
+
19
+ describe "AutoReload" do
20
+
21
+ before :all do
22
+ FileUtils.mkdir('tmp') unless File.exist?('tmp')
23
+ end
24
+
25
+ it "should autoreload" do
26
+ # create a library
27
+ library = Pathname.new('tmp/library.rb')
28
+ library.write 'def foo; 1; end'
29
+
30
+ # setup the autoreload
31
+ autoreload(library.to_s, :interval => 1) #, :verbose=>true)
32
+
33
+ # require it
34
+ require "#{library}"
35
+
36
+ # check the number
37
+ foo.should == 1
38
+
39
+ # wait is needed for time stamp to not be same with the next file.
40
+ sleep 1
41
+
42
+ # recreate the file
43
+ library.write 'def foo; 2; end'
44
+
45
+ # wait again for the autoreload loop to repeat.
46
+ sleep 2
47
+
48
+ # check the number again
49
+ foo.should == 2
50
+
51
+ # clean up
52
+ library.unlink
53
+ end
54
+
55
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoreload
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 17
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 2
8
- - 0
9
- version: 0.2.0
8
+ - 3
9
+ - 1
10
+ version: 0.3.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Kouichirou Eto
@@ -15,10 +16,37 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-06-02 00:00:00 -04:00
19
+ date: 2011-05-15 00:00:00 -04:00
19
20
  default_executable:
20
- dependencies: []
21
-
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: syckle
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
22
50
  description: Autoreload automatically reloads library files when they have been updated. It is especailly useful when testing stateless services such as web applications.
23
51
  email: rubyworks-mailinglist@googlegroups.com
24
52
  executables: []
@@ -28,49 +56,52 @@ extensions: []
28
56
  extra_rdoc_files:
29
57
  - README.rdoc
30
58
  files:
59
+ - .ruby
31
60
  - lib/autoreload/lookup.rb
32
61
  - lib/autoreload/reloader.rb
62
+ - lib/autoreload/version.rb
33
63
  - lib/autoreload.rb
34
- - test/test_autoreload.rb
35
- - test/test_helper.rb
36
- - PROFILE
37
- - LICENSE
64
+ - spec/autoreload_spec.rb
65
+ - HISTORY.rdoc
38
66
  - README.rdoc
39
- - HISTORY
40
- - VERSION
67
+ - GPL3.txt
68
+ - COPYING.rdoc
41
69
  has_rdoc: true
42
70
  homepage: http://rubyworks.github.com/autoreload
43
- licenses: []
44
-
71
+ licenses:
72
+ - Apache 2.0
45
73
  post_install_message:
46
74
  rdoc_options:
47
75
  - --title
48
- - Autoreload API
76
+ - AutoReload API
49
77
  - --main
50
78
  - README.rdoc
51
79
  require_paths:
52
80
  - lib
53
81
  required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
54
83
  requirements:
55
84
  - - ">="
56
85
  - !ruby/object:Gem::Version
86
+ hash: 3
57
87
  segments:
58
88
  - 0
59
89
  version: "0"
60
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
61
92
  requirements:
62
93
  - - ">="
63
94
  - !ruby/object:Gem::Version
95
+ hash: 3
64
96
  segments:
65
97
  - 0
66
98
  version: "0"
67
99
  requirements: []
68
100
 
69
101
  rubyforge_project: autoreload
70
- rubygems_version: 1.3.6
102
+ rubygems_version: 1.3.7
71
103
  signing_key:
72
104
  specification_version: 3
73
105
  summary: Automatically reload library files
74
- test_files:
75
- - test/test_autoreload.rb
76
- - test/test_helper.rb
106
+ test_files: []
107
+