sinatra-reloader 0.5.0 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- metadata +31 -109
- data/LICENSE +0 -27
- data/README.md +0 -43
- data/lib/sinatra/reloader.rb +0 -124
- data/spec/sinatra/reloader_spec.rb +0 -89
- data/spec/spec_helper.rb +0 -4
metadata
CHANGED
@@ -1,133 +1,55 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-reloader
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
- 0
|
10
|
-
version: 0.5.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Konstantin Haase
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
name: sinatra-advanced-routes
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 11
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 5
|
33
|
-
- 0
|
34
|
-
version: 0.5.0
|
35
|
-
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: sinatra-test-helper
|
39
|
-
prerelease: false
|
40
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
hash: 11
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
- 5
|
49
|
-
- 0
|
50
|
-
version: 0.5.0
|
51
|
-
type: :development
|
52
|
-
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: sinatra
|
55
|
-
prerelease: false
|
56
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
12
|
+
date: 2011-10-28 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra-contrib
|
16
|
+
requirement: &2152420600 !ruby/object:Gem::Requirement
|
57
17
|
none: false
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
segments:
|
63
|
-
- 1
|
64
|
-
- 0
|
65
|
-
version: "1.0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
66
22
|
type: :runtime
|
67
|
-
version_requirements: *id003
|
68
|
-
- !ruby/object:Gem::Dependency
|
69
|
-
name: rspec
|
70
23
|
prerelease: false
|
71
|
-
|
72
|
-
|
73
|
-
requirements:
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
hash: 27
|
77
|
-
segments:
|
78
|
-
- 1
|
79
|
-
- 3
|
80
|
-
- 0
|
81
|
-
version: 1.3.0
|
82
|
-
type: :development
|
83
|
-
version_requirements: *id004
|
84
|
-
description: Smart and fast code reloader for Sinatra (part of BigBand).
|
24
|
+
version_requirements: *2152420600
|
25
|
+
description: ! 'Dummy gem, sinatra-reloader is now part of sinatra-contrib: http://www.sinatrarb.com/contrib/'
|
85
26
|
email: konstantin.mailinglists@googlemail.com
|
86
27
|
executables: []
|
87
|
-
|
88
28
|
extensions: []
|
89
|
-
|
90
29
|
extra_rdoc_files: []
|
91
|
-
|
92
|
-
|
93
|
-
- lib/sinatra/reloader.rb
|
94
|
-
- spec/sinatra/reloader_spec.rb
|
95
|
-
- spec/spec_helper.rb
|
96
|
-
- README.md
|
97
|
-
- LICENSE
|
98
|
-
has_rdoc: yard
|
99
|
-
homepage: http://github.com/rkh/sinatra-reloader
|
30
|
+
files: []
|
31
|
+
homepage: http://github.com/sinatra/sinatra-contrib
|
100
32
|
licenses: []
|
101
|
-
|
102
33
|
post_install_message:
|
103
34
|
rdoc_options: []
|
104
|
-
|
105
|
-
require_paths:
|
35
|
+
require_paths:
|
106
36
|
- lib
|
107
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
38
|
none: false
|
109
|
-
requirements:
|
110
|
-
- -
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
|
113
|
-
|
114
|
-
- 0
|
115
|
-
version: "0"
|
116
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
44
|
none: false
|
118
|
-
requirements:
|
119
|
-
- -
|
120
|
-
- !ruby/object:Gem::Version
|
121
|
-
|
122
|
-
segments:
|
123
|
-
- 0
|
124
|
-
version: "0"
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
125
49
|
requirements: []
|
126
|
-
|
127
50
|
rubyforge_project:
|
128
|
-
rubygems_version: 1.
|
51
|
+
rubygems_version: 1.8.10
|
129
52
|
signing_key:
|
130
53
|
specification_version: 3
|
131
|
-
summary:
|
54
|
+
summary: Dummy gem, sinatra-reloader is now part of sinatra-contrib.
|
132
55
|
test_files: []
|
133
|
-
|
data/LICENSE
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
copyright (c) 2010 Konstantin Haase. All rights reserved.
|
2
|
-
|
3
|
-
Developed by: Konstantin Haase
|
4
|
-
http://github.com/rkh/big_band
|
5
|
-
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
-
of this software and associated documentation files (the "Software"), to
|
8
|
-
deal with the Software without restriction, including without limitation the
|
9
|
-
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10
|
-
sell copies of the Software, and to permit persons to whom the Software is
|
11
|
-
furnished to do so, subject to the following conditions:
|
12
|
-
1. Redistributions of source code must retain the above copyright notice,
|
13
|
-
this list of conditions and the following disclaimers.
|
14
|
-
2. Redistributions in binary form must reproduce the above copyright
|
15
|
-
notice, this list of conditions and the following disclaimers in the
|
16
|
-
documentation and/or other materials provided with the distribution.
|
17
|
-
3. Neither the name of Konstantin Haase, nor the names of other contributors
|
18
|
-
may be used to endorse or promote products derived from this Software without
|
19
|
-
specific prior written permission.
|
20
|
-
|
21
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
24
|
-
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
26
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
27
|
-
WITH THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
Sinatra::Reloader
|
2
|
-
=================
|
3
|
-
|
4
|
-
Advanced code reloader for [Sinatra](http://sinatrarb.com). Reloads only files that have
|
5
|
-
changed and automatically detects orphaned routes that have to be removed. Most other
|
6
|
-
implementations delete all routes and reload all code if one file changed, which takes way
|
7
|
-
more time than reloading only one file, especially in larger projects. Files defining
|
8
|
-
routes will be added to the reload list per default. Avoid reloading with dont_reload. Add
|
9
|
-
other files to the reload list with also_reload.
|
10
|
-
|
11
|
-
BigBand
|
12
|
-
-------
|
13
|
-
|
14
|
-
Sinatra::Reloader is part of the [BigBand](http://github.com/rkh/big_band) stack.
|
15
|
-
Check it out if you are looking for other fancy Sinatra extensions.
|
16
|
-
|
17
|
-
BigBand will setup the reloader automatically, but only in development mode.
|
18
|
-
|
19
|
-
Installation
|
20
|
-
------------
|
21
|
-
|
22
|
-
gem install sinatra-reloader
|
23
|
-
|
24
|
-
Usage
|
25
|
-
-----
|
26
|
-
|
27
|
-
Simple example:
|
28
|
-
|
29
|
-
require "sinatra"
|
30
|
-
require "sinatra/reloader" if development?
|
31
|
-
|
32
|
-
More complex:
|
33
|
-
|
34
|
-
require "sinatra/base"
|
35
|
-
require "sinatra/reloader"
|
36
|
-
|
37
|
-
class Foo < Sinatra::Base
|
38
|
-
configure(:development) do
|
39
|
-
register Sinatra::Reloader
|
40
|
-
also_reload "app/models/*.rb"
|
41
|
-
dont_reload "lib/**/*.rb"
|
42
|
-
end
|
43
|
-
end
|
data/lib/sinatra/reloader.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
require "monkey-lib"
|
2
|
-
require "sinatra/base"
|
3
|
-
require "sinatra/sugar"
|
4
|
-
require "sinatra/advanced_routes"
|
5
|
-
|
6
|
-
module Sinatra
|
7
|
-
Base.ignore_caller
|
8
|
-
|
9
|
-
module Reloader
|
10
|
-
class FileWatcher < Array
|
11
|
-
attr_reader :file, :mtime, :inline_templates, :app
|
12
|
-
extend Enumerable
|
13
|
-
@map ||= {}
|
14
|
-
|
15
|
-
def self.register(route)
|
16
|
-
new(route.file, route.app) << route if route.file?
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.new(file, app)
|
20
|
-
file = file.expand_path
|
21
|
-
begin
|
22
|
-
file = file.realpath
|
23
|
-
rescue Errno::ENOENT
|
24
|
-
end
|
25
|
-
@map[file] ||= super
|
26
|
-
end
|
27
|
-
|
28
|
-
class << self
|
29
|
-
alias [] new
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.each(&block)
|
33
|
-
@map.values.each(&block)
|
34
|
-
end
|
35
|
-
|
36
|
-
def initialize(file, app)
|
37
|
-
@reload, @file, @app = true, file, app
|
38
|
-
@mtime = File.exist?(file) ? File.mtime(file) : Time.at(0)
|
39
|
-
super()
|
40
|
-
end
|
41
|
-
|
42
|
-
def changed?
|
43
|
-
!File.exist? file or @mtime != File.mtime(file)
|
44
|
-
end
|
45
|
-
|
46
|
-
def dont_reload!(dont = true)
|
47
|
-
@reload = !dont
|
48
|
-
end
|
49
|
-
|
50
|
-
def reload?
|
51
|
-
@reload and changed?
|
52
|
-
end
|
53
|
-
|
54
|
-
def reload
|
55
|
-
reload! if reload?
|
56
|
-
end
|
57
|
-
|
58
|
-
def inline_templates?
|
59
|
-
!!inline_templates
|
60
|
-
end
|
61
|
-
|
62
|
-
def inline_templates!
|
63
|
-
@inline_templates = true
|
64
|
-
end
|
65
|
-
|
66
|
-
def reload!
|
67
|
-
each { |route| route.deactivate }
|
68
|
-
$LOADED_FEATURES.delete file
|
69
|
-
clear
|
70
|
-
if File.exist? file
|
71
|
-
app.set :inline_templates, file if inline_templates?
|
72
|
-
@mtime = File.mtime(file)
|
73
|
-
require file
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
module ClassMethods
|
79
|
-
def dont_reload(*files)
|
80
|
-
if [true, false].include? files.last then dont = files.pop
|
81
|
-
else dont = true
|
82
|
-
end
|
83
|
-
files.flatten.each do |file|
|
84
|
-
# Rubinius and JRuby ignore block passed to glob.
|
85
|
-
Dir.glob(file).each { |f| FileWatcher[f, self].dont_reload! dont }
|
86
|
-
FileWatcher[file, self].dont_reload! dont
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def also_reload(*files)
|
91
|
-
dont_reload(files, false)
|
92
|
-
end
|
93
|
-
|
94
|
-
def inline_templates=(file = nil)
|
95
|
-
file = (file.nil? || file == true) ? caller_files.first : (file || $0)
|
96
|
-
FileWatcher[file, self].inline_templates!
|
97
|
-
super
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def self.registered(klass)
|
102
|
-
klass.register AdvancedRoutes
|
103
|
-
klass.extend ClassMethods
|
104
|
-
klass.each_route { |route| advanced_route_added(route) }
|
105
|
-
klass.enable :reload_templates
|
106
|
-
klass.before { Reloader.reload_routes }
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.advanced_route_added(route)
|
110
|
-
FileWatcher.register(route)
|
111
|
-
end
|
112
|
-
|
113
|
-
def self.thread_safe?
|
114
|
-
Thread and Thread.list.size > 1 and Thread.respond_to? :exclusive
|
115
|
-
end
|
116
|
-
|
117
|
-
def self.reload_routes(thread_safe = true)
|
118
|
-
return Thread.exclusive { reload_routes(false) } if thread_safe and thread_safe?
|
119
|
-
FileWatcher.each { |file| file.reload }
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
register Reloader
|
124
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
-
|
3
|
-
describe Sinatra::Reloader do
|
4
|
-
it_should_behave_like 'sinatra'
|
5
|
-
|
6
|
-
def app_file(file, content)
|
7
|
-
file = File.expand_path(file, @temp_dir)
|
8
|
-
old_mtime = File.exist?(file) ? File.mtime(file) : Time.at(0)
|
9
|
-
new_mtime = old_mtime
|
10
|
-
# this is eventually faster than a hard coded sleep 1, also it adjusts to the systems
|
11
|
-
# mtime granularity
|
12
|
-
until new_mtime > old_mtime
|
13
|
-
File.open(file, "w") do |f|
|
14
|
-
f << "class ::ExampleApp < Sinatra::Base; #{content}; end\n"
|
15
|
-
yield f if block_given?
|
16
|
-
end
|
17
|
-
File.utime File.atime(file), old_mtime + 10, file unless ENV['MTIME']
|
18
|
-
new_mtime = File.mtime file
|
19
|
-
# ok, let's not generate too much io
|
20
|
-
sleep 0.1 if new_mtime == old_mtime
|
21
|
-
end
|
22
|
-
require file
|
23
|
-
file
|
24
|
-
end
|
25
|
-
|
26
|
-
def app
|
27
|
-
::ExampleApp
|
28
|
-
end
|
29
|
-
|
30
|
-
before do
|
31
|
-
@temp_dir ||= File.expand_path "../../temp", __FILE__
|
32
|
-
rm_rf @temp_dir
|
33
|
-
mkdir_p @temp_dir
|
34
|
-
$LOADED_FEATURES.reject! { |f| f =~ /^#{@temp_dir}/ }
|
35
|
-
class ::ExampleApp < Sinatra::Base
|
36
|
-
reset!
|
37
|
-
register Sinatra::Reloader
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
after :all do
|
42
|
-
rm_rf @temp_dir
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should reload files" do
|
46
|
-
app_file("example_app.rb", "get('/foo') { 'foo' }")
|
47
|
-
browse_route(:get, '/foo').body.should == 'foo'
|
48
|
-
app_file("example_app.rb", "get('/foo') { 'bar' }")
|
49
|
-
browse_route(:get, '/foo').body.should == 'bar'
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should not affact other routes" do
|
53
|
-
app_file("example_app.rb", "get('/foo') { 'foo' }")
|
54
|
-
app_file("example_app2.rb", "get('/bar') { 'bar' }")
|
55
|
-
browse_route(:get, '/bar').body.should == 'bar'
|
56
|
-
app_file("example_app.rb", "get('/foo') { 'bar' }")
|
57
|
-
browse_route(:get, '/bar').body.should == 'bar'
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should respect dont_reload" do
|
61
|
-
file = app_file("example_app3.rb", "get('/baz') { 'foo' }")
|
62
|
-
app.dont_reload file
|
63
|
-
app_file("example_app3.rb", "get('/baz') { 'bar' }")
|
64
|
-
browse_route(:get, '/baz').body.should == 'foo'
|
65
|
-
end
|
66
|
-
|
67
|
-
it "reloads inline templates" do
|
68
|
-
file = app_file("example_app4.rb", "get('/foo') { haml :foo }") { |f| f.puts "__END__", "@@foo", "foo" }
|
69
|
-
app.set :inline_templates, file
|
70
|
-
browse_route(:get, '/foo').body.strip.should == "foo"
|
71
|
-
app_file("example_app4.rb", "get('/foo') { haml :foo }") { |f| f.puts "__END__", "@@foo", "bar" }
|
72
|
-
browse_route(:get, '/foo').body.strip.should == "bar"
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should not readd middleware" do
|
76
|
-
3.times do
|
77
|
-
app_file "example_app5.rb", <<-RUBY
|
78
|
-
use Rack::Config do |env|
|
79
|
-
env['some.counter'] ||= 0
|
80
|
-
env['some.counter'] += 1
|
81
|
-
$counter = env['some.counter']
|
82
|
-
end
|
83
|
-
RUBY
|
84
|
-
browse_route :get, '/foo'
|
85
|
-
end
|
86
|
-
$counter.should == 1
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
data/spec/spec_helper.rb
DELETED