sinatra-reloader 0.4.0.a → 0.4.0.b

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -16,9 +16,21 @@ Check it out if you are looking for other fancy Sinatra extensions.
16
16
 
17
17
  BigBand will setup the reloader automatically, but only in development mode.
18
18
 
19
+ Installation
20
+ ------------
21
+
22
+ gem install sinatra-reloader --prerelease
23
+
19
24
  Usage
20
25
  -----
21
26
 
27
+ Simple example:
28
+
29
+ require "sinatra"
30
+ require "sinatra/reloader" if development?
31
+
32
+ More complex:
33
+
22
34
  require "sinatra/base"
23
35
  require "sinatra/reloader"
24
36
 
@@ -6,23 +6,6 @@ require "sinatra/advanced_routes"
6
6
  module Sinatra
7
7
  Base.ignore_caller
8
8
 
9
- # Advanced reloader for sinatra. Reloads only files that have changed and automatically
10
- # detects orphaned routes that have to be removed. Files defining routes will be added
11
- # to the reload list per default. Avoid reloading with dont_reload. Add other files to
12
- # the reload list with also_reload.
13
- #
14
- # Usage:
15
- #
16
- # require "big_band"
17
- # class Foo < Sinatra::Base
18
- # configure(:development) do
19
- # register BigBand::Reloader
20
- # also_reload "app/models/*.rb"
21
- # dont_reload "lib/**/*.rb"
22
- # end
23
- # end
24
- #
25
- # Per default this will only be acitvated in development mode.
26
9
  module Reloader
27
10
 
28
11
  class FileWatcher < Array
@@ -37,7 +20,12 @@ module Sinatra
37
20
  end
38
21
 
39
22
  def self.new(file)
40
- @map[file.expand_path] ||= super
23
+ file = file.expand_path
24
+ begin
25
+ file = file.realpath
26
+ rescue Errno::ENOENT
27
+ end
28
+ @map[file] ||= super
41
29
  end
42
30
 
43
31
  class << self
@@ -49,8 +37,8 @@ module Sinatra
49
37
  end
50
38
 
51
39
  def initialize(file)
52
- @reload = true
53
- @file, @mtime = file, File.mtime(file)
40
+ @reload, @file = true, file
41
+ @mtime = File.exist?(file) ? File.mtime(file) : Time.at(0)
54
42
  super()
55
43
  end
56
44
 
@@ -88,7 +76,9 @@ module Sinatra
88
76
  else dont = true
89
77
  end
90
78
  files.flatten.each do |file|
91
- Dir.glob(file) { |f| FileWatcher[f].dont_reload! dont }
79
+ # Rubinius and JRuby ignore block passed to glob.
80
+ Dir.glob(file).each { |f| FileWatcher[f].dont_reload! dont }
81
+ FileWatcher[file].dont_reload! dont
92
82
  end
93
83
  end
94
84
 
@@ -118,4 +108,7 @@ module Sinatra
118
108
  end
119
109
 
120
110
  end
111
+
112
+ register Reloader
113
+
121
114
  end
@@ -3,22 +3,32 @@ require File.expand_path("../../spec_helper", __FILE__)
3
3
  describe Sinatra::Reloader do
4
4
 
5
5
  def app_file(file, content, go_sleeping = true)
6
- sleep 1 if go_sleeping
7
6
  file = File.expand_path(file, @temp_dir)
8
- File.open(file, "w") { |f| f << "class ExampleApp < Sinatra::Base; #{content}; end" }
7
+ old_mtime = File.exist?(file) ? File.mtime(file) : Time.at(0)
8
+ new_mtime = old_mtime
9
+ # this is eventually faster than a hard coded sleep 1, also it adjusts to the systems
10
+ # mtime granularity
11
+ until new_mtime > old_mtime
12
+ File.open(file, "w") { |f| f << "class ::ExampleApp < Sinatra::Base; #{content}; end" }
13
+ new_mtime = File.mtime file
14
+ # ok, let's not generate too much io
15
+ sleep 0.1 if new_mtime == old_mtime
16
+ end
9
17
  require file
10
18
  file
11
19
  end
12
20
 
13
21
  def app
14
- ExampleApp
22
+ ::ExampleApp
15
23
  end
16
24
 
17
- before :all do
25
+ before do
18
26
  @temp_dir ||= File.expand_path "../../temp", __FILE__
19
27
  rm_rf @temp_dir
20
28
  mkdir_p @temp_dir
21
- class ExampleApp < Sinatra::Base
29
+ $LOADED_FEATURES.reject! { |f| f =~ /^#{@temp_dir}/ }
30
+ class ::ExampleApp < Sinatra::Base
31
+ reset!
22
32
  register Sinatra::Reloader
23
33
  end
24
34
  end
@@ -36,14 +46,14 @@ describe Sinatra::Reloader do
36
46
 
37
47
  it "should not affact other routes" do
38
48
  app_file("example_app.rb", "get('/foo') { 'foo' }")
39
- app_file("example_app2.rb", "get('/bar') { 'bar' }", false)
49
+ app_file("example_app2.rb", "get('/bar') { 'bar' }")
40
50
  browse_route(:get, '/bar').body.should == 'bar'
41
51
  app_file("example_app.rb", "get('/foo') { 'bar' }")
42
52
  browse_route(:get, '/bar').body.should == 'bar'
43
53
  end
44
54
 
45
55
  it "should respect dont_reload" do
46
- file = app_file("example_app3.rb", "get('/baz') { 'foo' }", false)
56
+ file = app_file("example_app3.rb", "get('/baz') { 'foo' }")
47
57
  app.dont_reload file
48
58
  app_file("example_app3.rb", "get('/baz') { 'bar' }")
49
59
  browse_route(:get, '/baz').body.should == 'foo'
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  require "sinatra/rspec"
2
2
  require "sinatra/reloader"
3
3
  require "fileutils"
4
- require "monkey"
5
- Sinatra::Base.set :environment, :test
6
4
  include FileUtils
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-reloader
3
- version: &id001 !ruby/object:Gem::Version
4
- version: 0.4.0.a
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 0
9
+ - b
10
+ version: 0.4.0.b
5
11
  platform: ruby
6
12
  authors:
7
13
  - Konstantin Haase
@@ -9,65 +15,97 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-02-16 00:00:00 +01:00
18
+ date: 2010-03-26 00:00:00 +01:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: monkey-lib
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
20
25
  requirements:
21
- - - "="
22
- - *id001
23
- version:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 4
31
+ - 0
32
+ - a
33
+ version: 0.4.0.a
34
+ type: :runtime
35
+ version_requirements: *id001
24
36
  - !ruby/object:Gem::Dependency
25
37
  name: sinatra-advanced-routes
26
- type: :runtime
27
- version_requirement:
28
- version_requirements: !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
29
40
  requirements:
30
- - - "="
31
- - *id001
32
- version:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ - 4
46
+ - 0
47
+ - a
48
+ version: 0.4.0.a
49
+ type: :runtime
50
+ version_requirements: *id002
33
51
  - !ruby/object:Gem::Dependency
34
52
  name: sinatra-sugar
35
- type: :runtime
36
- version_requirement:
37
- version_requirements: !ruby/object:Gem::Requirement
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
38
55
  requirements:
39
- - - "="
40
- - *id001
41
- version:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ - 4
61
+ - 0
62
+ - a
63
+ version: 0.4.0.a
64
+ type: :runtime
65
+ version_requirements: *id003
42
66
  - !ruby/object:Gem::Dependency
43
67
  name: sinatra-test-helper
44
- type: :development
45
- version_requirement:
46
- version_requirements: !ruby/object:Gem::Requirement
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
47
70
  requirements:
48
- - - "="
49
- - *id001
50
- version:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ - 4
76
+ - 0
77
+ - a
78
+ version: 0.4.0.a
79
+ type: :development
80
+ version_requirements: *id004
51
81
  - !ruby/object:Gem::Dependency
52
82
  name: sinatra
53
- type: :runtime
54
- version_requirement:
55
- version_requirements: !ruby/object:Gem::Requirement
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
56
85
  requirements:
57
86
  - - ">="
58
87
  - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ - 9
91
+ - 4
59
92
  version: 0.9.4
60
- version:
93
+ type: :runtime
94
+ version_requirements: *id005
61
95
  - !ruby/object:Gem::Dependency
62
96
  name: rspec
63
- type: :development
64
- version_requirement:
65
- version_requirements: !ruby/object:Gem::Requirement
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
66
99
  requirements:
67
100
  - - ">="
68
101
  - !ruby/object:Gem::Version
102
+ segments:
103
+ - 1
104
+ - 3
105
+ - 0
69
106
  version: 1.3.0
70
- version:
107
+ type: :development
108
+ version_requirements: *id006
71
109
  description: Smart and fast code reloader for Sinatra (part of BigBand).
72
110
  email: konstantin.mailinglists@googlemail.com
73
111
  executables: []
@@ -94,18 +132,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
132
  requirements:
95
133
  - - ">="
96
134
  - !ruby/object:Gem::Version
135
+ segments:
136
+ - 0
97
137
  version: "0"
98
- version:
99
138
  required_rubygems_version: !ruby/object:Gem::Requirement
100
139
  requirements:
101
140
  - - ">"
102
141
  - !ruby/object:Gem::Version
142
+ segments:
143
+ - 1
144
+ - 3
145
+ - 1
103
146
  version: 1.3.1
104
- version:
105
147
  requirements: []
106
148
 
107
149
  rubyforge_project:
108
- rubygems_version: 1.3.5
150
+ rubygems_version: 1.3.6
109
151
  signing_key:
110
152
  specification_version: 3
111
153
  summary: Smart and fast code reloader for Sinatra (part of BigBand).