autoreload 0.0.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.
data/Changes.txt ADDED
@@ -0,0 +1,48 @@
1
+ == 2007-07-05
2
+
3
+ * Changes.txt: New file. Moved from ChangeLog.
4
+ * ChangeLog: Deleted.
5
+
6
+ * bin: Deleted.
7
+
8
+ * lib/autoreload.rb: Make it start from class method.
9
+
10
+ * lib/autoreload/version.rb: Removed.
11
+
12
+ * lib/autoreload.rb: Reformat.
13
+
14
+ * examples/sample1.rb: New file.
15
+ * examples/foo.rb: New file.
16
+
17
+ * default_task.rb: New file. Splited from Rakefile.
18
+ * Rakefile: Follow.
19
+ * script/lib-txt2html.rb: New file.
20
+ * script/makemanifest.rb: New file.
21
+
22
+ * License.txt: Update license to Ruby license.
23
+
24
+ * test/test_autoreload.rb: Sometimes test is failed.
25
+
26
+ * default_task.rb: Check file exist in chmod task.
27
+
28
+ * default_task.rb: Specify version and download.
29
+ * scripts/lib-txt2html.rb: Remove dependency.
30
+ * scripts/txt2html: Follow.
31
+
32
+ == 2007-07-04
33
+
34
+ * License.txt: created.
35
+ * README.txt: created.
36
+
37
+ * lib/autoreload/version.rb: Truncated.
38
+ * Rakefile: Ditto.
39
+
40
+ * lib/autoreload.rb: Created.
41
+ * test/test_autoreload.rb: Ditto.
42
+
43
+ * lib/autoreload.rb: Refactoring.
44
+
45
+ == 2007-07-04
46
+
47
+ * Init.
48
+
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2007-07-01
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,55 @@
1
+ Copyright (c) 2003-2007 Kouichirou Eto
2
+
3
+ You can redistribute it and/or modify it under either the terms of the GPL
4
+ version 2 (see the file GPL), or the conditions below:
5
+
6
+ 1. You may make and give away verbatim copies of the source form of the
7
+ software without restriction, provided that you duplicate all of the
8
+ original copyright notices and associated disclaimers.
9
+
10
+ 2. You may modify your copy of the software in any way, provided that
11
+ you do at least ONE of the following:
12
+
13
+ a) place your modifications in the Public Domain or otherwise
14
+ make them Freely Available, such as by posting said
15
+ modifications to Usenet or an equivalent medium, or by allowing
16
+ the author to include your modifications in the software.
17
+
18
+ b) use the modified software only within your corporation or
19
+ organization.
20
+
21
+ c) give non-standard binaries non-standard names, with
22
+ instructions on where to get the original software distribution.
23
+
24
+ d) make other distribution arrangements with the author.
25
+
26
+ 3. You may distribute the software in object code or binary form,
27
+ provided that you do at least ONE of the following:
28
+
29
+ a) distribute the binaries and library files of the software,
30
+ together with instructions (in the manual page or equivalent)
31
+ on where to get the original distribution.
32
+
33
+ b) accompany the distribution with the machine-readable source of
34
+ the software.
35
+
36
+ c) give non-standard binaries non-standard names, with
37
+ instructions on where to get the original software distribution.
38
+
39
+ d) make other distribution arrangements with the author.
40
+
41
+ 4. You may modify and include the part of the software into any other
42
+ software (possibly commercial). But some files in the distribution
43
+ are not written by the author, so that they are not under these terms.
44
+
45
+ 5. The scripts and library files supplied as input to or produced as
46
+ output from the software do not automatically fall under the
47
+ copyright of the software, but belong to whomever generated them,
48
+ and may be sold commercially, and may be aggregated with this
49
+ software.
50
+
51
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
52
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
53
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
54
+ PURPOSE.
55
+
data/Manifest.txt ADDED
@@ -0,0 +1,21 @@
1
+ Changes.txt
2
+ History.txt
3
+ License.txt
4
+ Manifest.txt
5
+ README.txt
6
+ Rakefile
7
+ default_task.rb
8
+ examples/foo.rb
9
+ examples/sample1.rb
10
+ lib/autoreload.rb
11
+ scripts/lib-txt2html.rb
12
+ scripts/makemanifest.rb
13
+ scripts/txt2html
14
+ setup.rb
15
+ test/test_autoreload.rb
16
+ test/test_helper.rb
17
+ website/index.html
18
+ website/index.txt
19
+ website/javascripts/rounded_corners_lite.inc.js
20
+ website/stylesheets/screen.css
21
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,5 @@
1
+ README for autoreload
2
+ =====================
3
+
4
+ 'autoreload' reload the library if the file is updated.
5
+
data/Rakefile ADDED
@@ -0,0 +1,80 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+ require File.join(File.dirname(__FILE__), 'default_task')
4
+ require File.join(File.dirname(__FILE__), 'lib', 'autoreload')
5
+
6
+ AUTHOR = 'FIXME full name' # can also be an array of Authors
7
+ EMAIL = "FIXME email"
8
+ DESCRIPTION = "description of gem"
9
+ GEM_NAME = 'autoreload' # what ppl will type to install your gem
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ def rubyforge_username
14
+ unless @config
15
+ begin
16
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
17
+ rescue
18
+ puts <<-EOS
19
+ ERROR: No rubyforge config file found: #{@config_file}"
20
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
21
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
22
+ EOS
23
+ # "
24
+ exit
25
+ end
26
+ end
27
+ @rubyforge_username ||= @config["username"]
28
+ end
29
+
30
+ RUBYFORGE_PROJECT = 'autoreload' # The unix name for your project
31
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
32
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
33
+
34
+ NAME = "autoreload"
35
+ REV = nil
36
+ # UNCOMMENT IF REQUIRED:
37
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
38
+ VERS = AutoReload::VERSION::STRING + (REV ? ".#{REV}" : "")
39
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
40
+ RDOC_OPTS = ['--quiet', '--title', 'autoreload documentation',
41
+ "--opname", "index.html",
42
+ "--line-numbers",
43
+ "--main", "README",
44
+ "--inline-source"]
45
+
46
+ # Generate all the Rake tasks
47
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
48
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
49
+ p.author = AUTHOR
50
+ p.description = DESCRIPTION
51
+ p.email = EMAIL
52
+ p.summary = DESCRIPTION
53
+ p.url = HOMEPATH
54
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
55
+ p.test_globs = ["test/**/test_*.rb"]
56
+ p.clean_globs |= CLEAN #An array of file patterns to delete on clean.
57
+
58
+ # == Optional
59
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
60
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
61
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
62
+ end
63
+
64
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
65
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
66
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
67
+
68
+ # clear current task
69
+ t = Rake.application.lookup(:install_gem)
70
+ t.clear_actions if t
71
+
72
+ # redefine task
73
+ task :install_gem => [:clean, :package] do
74
+ if /mswin32/ =~ RUBY_PLATFORM || /cygwin/ =~ RUBY_PLATFORM
75
+ sh "gem.cmd install pkg/*.gem" # for Cygwin
76
+ else
77
+ sh "sudo gem install pkg/*.gem"
78
+ end
79
+ end
80
+
data/default_task.rb ADDED
@@ -0,0 +1,129 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'hoe'
10
+ begin
11
+ require 'spec/rake/spectask'
12
+ rescue LoadError
13
+ puts 'To use rspec for testing you must install rspec gem:'
14
+ puts '$ sudo gem install rspec'
15
+ exit
16
+ end
17
+
18
+ class Hoe
19
+ def extra_deps
20
+ @extra_deps.reject { |x| Array(x).first == 'hoe' }
21
+ end
22
+ end
23
+
24
+ desc 'Generate website files'
25
+ task :website_generate do
26
+ require 'scripts/lib-txt2html'
27
+ t2h = Txt2Html.new
28
+ Dir['website/**/*.txt'].each do |txt|
29
+ puts txt
30
+ version = VERS
31
+ download = DOWNLOAD_PATH
32
+ t2h.translate(txt, txt.gsub(/txt$/, 'html'), version, download)
33
+ end
34
+ end
35
+
36
+ # add chmod.
37
+ task :website_generate do
38
+ sh %{ chmod -R go+rx website }
39
+ end
40
+
41
+ desc 'Upload website files to rubyforge'
42
+ task :website_upload do
43
+ host = "#{rubyforge_username}@rubyforge.org"
44
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
45
+ local_dir = 'website'
46
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
47
+ end
48
+
49
+ desc 'Generate and upload website files'
50
+ task :website => [:website_generate, :website_upload, :publish_docs]
51
+
52
+ desc 'Release the website and new gem version'
53
+ task :deploy => [:check_version, :website, :release] do
54
+ puts "Remember to create SVN tag:"
55
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
56
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
57
+ puts "Suggested comment:"
58
+ puts "Tagging release #{CHANGES}"
59
+ end
60
+
61
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
62
+ task :local_deploy => [:website_generate, :install_gem]
63
+
64
+ task :check_version do
65
+ unless ENV['VERSION']
66
+ puts 'Must pass a VERSION=x.y.z release version'
67
+ exit
68
+ end
69
+ unless ENV['VERSION'] == VERS
70
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
71
+ exit
72
+ end
73
+ end
74
+
75
+ desc "Run the specs under spec/models"
76
+ Spec::Rake::SpecTask.new do |t|
77
+ t.spec_opts = ['--options', "spec/spec.opts"]
78
+ t.spec_files = FileList['spec/*_spec.rb']
79
+ t.libs << "lib"
80
+ end
81
+
82
+ # add chmod.
83
+ task :docs do
84
+ sh %{ chmod -R go+rx doc }
85
+ end
86
+
87
+ # clear current task
88
+ module Rake
89
+ class Task
90
+ def clear_actions
91
+ @actions.clear
92
+ end
93
+ end
94
+ end
95
+
96
+ task :clean => [:chmod]
97
+
98
+ CHMOD644 = FileList[%w(
99
+ Rakefile ChangeLog
100
+ **/*.txt
101
+ **/*.html
102
+ **/*.rhtml
103
+ **/*.js
104
+ **/*.css
105
+ **/*.rb
106
+ **/*.opts
107
+ )]
108
+ CHMOD755 = FileList[%w(scripts/*)]
109
+
110
+ desc 'Chmod all files.'
111
+ task :chmod do
112
+ CHMOD644.each {|f|
113
+ File.chmod 0644, f if File.exist? f
114
+ }
115
+ CHMOD755.each {|f|
116
+ File.chmod 0755, f if File.exist? f
117
+ }
118
+ end
119
+
120
+ desc 'Create Manifest.txt file.'
121
+ task :manifest => [:chmod, :clean] do
122
+ ruby "scripts/makemanifest.rb"
123
+ end
124
+
125
+ # Add tasks to gem
126
+ task :gem => [:manifest]
127
+
128
+ desc "Default task is to run specs"
129
+ task :default => [:spec]
data/examples/foo.rb ADDED
@@ -0,0 +1,6 @@
1
+ # foo.rb
2
+ # Change this file during 'sample1.rb' is running.
3
+
4
+ def foo
5
+ 1
6
+ end
@@ -0,0 +1,13 @@
1
+ # sample1.rb
2
+ # Run this script and change 'foo.rb' during this is running.
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../lib')
5
+ require 'autoreload'
6
+ require 'foo'
7
+
8
+ autoreload(1, true, 'sample1')
9
+
10
+ loop {
11
+ puts foo
12
+ sleep 1
13
+ }
data/lib/autoreload.rb ADDED
@@ -0,0 +1,100 @@
1
+ # Copyright (C) 2003-2007 Kouichirou Eto, All rights reserved.
2
+ # License: Ruby License
3
+
4
+ require 'thread'
5
+
6
+ module AutoReload #:nodoc:
7
+ module VERSION #:nodoc:
8
+ MAJOR = 0
9
+ MINOR = 0
10
+ TINY = 1
11
+ STRING = [MAJOR, MINOR, TINY].join('.')
12
+ end
13
+
14
+ class Reloader
15
+ def self.start(*a)
16
+ self.new(*a).start
17
+ end
18
+
19
+ DEFAULT_INTERVAL = 1
20
+
21
+ def initialize(interval = DEFAULT_INTERVAL,
22
+ verbose = false, name = nil) #:nodoc:
23
+ @interval = interval
24
+ @verbose = verbose
25
+ @name = name
26
+ @status = {}
27
+ @thread = nil
28
+ end
29
+
30
+ def start #:nodoc:
31
+ @thread = Thread.new {
32
+ loop {
33
+ begin
34
+ update
35
+ rescue Exception
36
+ warn 'update failed: ' + $!
37
+ end
38
+ sleep @interval
39
+ }
40
+ }
41
+ @thread.abort_on_exception = true
42
+ end
43
+
44
+ private
45
+
46
+ def warn(msg, out = $stderr)
47
+ msg = "#{@name}: #{msg}" if @name
48
+ out << msg + "\n"
49
+ # $stderr.puts()
50
+ end
51
+
52
+ def update
53
+ libs = [$0] + $"
54
+ libs.each {|lib|
55
+ check_lib(lib)
56
+ }
57
+ end
58
+
59
+ def check_lib(lib)
60
+ if @status[lib]
61
+ file, mtime = @status[lib]
62
+ return if ! FileTest.exist?(file) # file is disappered.
63
+ curtime = File.mtime(file).to_i
64
+ if mtime < curtime
65
+ if @verbose
66
+ warn "reload: '#{file}'"
67
+ end
68
+ load file # Load it.
69
+ @status[lib] = [file, curtime]
70
+ end
71
+ return
72
+ end
73
+
74
+ check_path = [''] + $LOAD_PATH
75
+ #check_path = ['']
76
+ check_path.each {|path|
77
+ file = File.join(path, lib)
78
+ file = lib if path.empty? # Check if the lib is a filename.
79
+ if FileTest.exist?(file)
80
+ @status[lib] = [file, File.mtime(file).to_i]
81
+ return
82
+ end
83
+ }
84
+
85
+ #raise "The library '#{lib}' is not found."
86
+ # $stdout.puts(message("The library '#{lib}' is not found.")) if @verbose
87
+ end
88
+
89
+ def get_status(file)
90
+ if FileTest.exist?(file)
91
+ return [file, File.mtime(file).to_i]
92
+ end
93
+ return nil
94
+ end
95
+ end
96
+ end
97
+
98
+ def autoreload(*a)
99
+ AutoReload::Reloader.start(*a)
100
+ end