impromptu 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/impromptu.gemspec +4 -2
- data/lib/impromptu/impromptu.rb +5 -1
- data/lib/impromptu/resource.rb +21 -1
- data/test/framework/copies/new_klass.rb +9 -0
- data/test/framework/copies/original_klass.rb +9 -0
- data/test/framework/lib/klass.rb +9 -0
- data/test/framework/lib/sub_klass.rb +4 -0
- data/test/test_integration.rb +22 -4
- metadata +5 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.5.0
|
data/impromptu.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{impromptu}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Will Cannings"]
|
12
|
-
s.date = %q{2011-01-
|
12
|
+
s.date = %q{2011-01-23}
|
13
13
|
s.description = %q{Component and dependency manager for Ruby}
|
14
14
|
s.email = %q{me@willcannings.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -44,6 +44,7 @@ Gem::Specification.new do |s|
|
|
44
44
|
"test/framework/folder_namespace/two_names.rb",
|
45
45
|
"test/framework/lib/group/klass2.rb",
|
46
46
|
"test/framework/lib/klass.rb",
|
47
|
+
"test/framework/lib/sub_klass.rb",
|
47
48
|
"test/framework/other/also.rb",
|
48
49
|
"test/framework/other/ignore.rb",
|
49
50
|
"test/framework/other/load.rb",
|
@@ -82,6 +83,7 @@ Gem::Specification.new do |s|
|
|
82
83
|
"test/framework/folder_namespace/two_names.rb",
|
83
84
|
"test/framework/lib/group/klass2.rb",
|
84
85
|
"test/framework/lib/klass.rb",
|
86
|
+
"test/framework/lib/sub_klass.rb",
|
85
87
|
"test/framework/other/also.rb",
|
86
88
|
"test/framework/other/ignore.rb",
|
87
89
|
"test/framework/other/load.rb",
|
data/lib/impromptu/impromptu.rb
CHANGED
@@ -15,13 +15,17 @@ module Impromptu
|
|
15
15
|
# have been marked as reloadable. Any modified files will be
|
16
16
|
# reloaded, any new files will have their assiciated resources
|
17
17
|
# inserted in the resource tree, and any removed files will be
|
18
|
-
# unloaded.
|
18
|
+
# unloaded. Any preloaded resources which are unloaded as a
|
19
|
+
# result of an update will automatically be reloaded again.
|
19
20
|
def self.update
|
20
21
|
components.each do |component|
|
21
22
|
component.folders.each do |folder|
|
22
23
|
folder.reload if folder.reloadable?
|
23
24
|
end
|
24
25
|
end
|
26
|
+
|
27
|
+
# force any unloaded preloading resources to reload
|
28
|
+
self.root_resource.reload_preloaded_resources
|
25
29
|
end
|
26
30
|
|
27
31
|
# Reset Impromptu by removing all known components and resources.
|
data/lib/impromptu/resource.rb
CHANGED
@@ -70,10 +70,26 @@ module Impromptu
|
|
70
70
|
|
71
71
|
# Unload the resource by undefining the constant representing it.
|
72
72
|
# Any resources contained within this resource will also be
|
73
|
-
# unloaded. This allows the resource to be garbage collected.
|
73
|
+
# unloaded. This allows the resource to be garbage collected. If
|
74
|
+
# the resource is a class, you can define a class method called
|
75
|
+
# 'descendants' that returns an array of references to subclasses.
|
76
|
+
# Any subclasses known to Impromptu will also be unloaded, just as
|
77
|
+
# namespaced children are. This prevents subclasses holding a
|
78
|
+
# reference to a stale version of a super class.
|
74
79
|
def unload
|
75
80
|
return unless loaded?
|
81
|
+
|
82
|
+
# unload namespaced children
|
76
83
|
@children.each_value(&:unload)
|
84
|
+
|
85
|
+
# unload descendants if they can be reloaded by impromptu
|
86
|
+
if reference.respond_to? :descendants
|
87
|
+
reference.descendants.each do |descendant|
|
88
|
+
resource = Impromptu.root_resource.child(descendant.name.to_sym)
|
89
|
+
resource.unload unless resource.nil?
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
77
93
|
unless @dont_undef
|
78
94
|
@parent.reference.send(:remove_const, @base_symbol)
|
79
95
|
@reference = nil
|
@@ -217,6 +233,10 @@ module Impromptu
|
|
217
233
|
@children.each_value(&:load_if_extending_stdlib)
|
218
234
|
end
|
219
235
|
|
236
|
+
# Loads this resource, and any child resources, if the resource is
|
237
|
+
# marked as requiring preloading, and the resource is not currently
|
238
|
+
# loaded. This loading may happen multiple times during the application
|
239
|
+
# life cycle depending on whether parent resources are reloaded and so on.
|
220
240
|
def reload_preloaded_resources
|
221
241
|
reload if !loaded? && preload?
|
222
242
|
@children.each_value(&:reload_preloaded_resources)
|
data/test/framework/lib/klass.rb
CHANGED
data/test/test_integration.rb
CHANGED
@@ -35,19 +35,20 @@ class TestIntegration < Test::Unit::TestCase
|
|
35
35
|
assert_equal nil, Impromptu.components['other'].namespace
|
36
36
|
end
|
37
37
|
|
38
|
-
should "05 start tracking
|
39
|
-
assert_equal
|
38
|
+
should "05 start tracking all files" do
|
39
|
+
assert_equal 3, Impromptu.components['framework'].folders.first.files.size
|
40
40
|
assert_equal 2, Impromptu.components['framework.extensions'].folders.first.files.size
|
41
41
|
assert_equal 3, Impromptu.components['other'].folders.first.files.size
|
42
42
|
assert_equal 2, Impromptu.components['private'].folders.first.files.size
|
43
43
|
assert_equal 2, Impromptu.components['folder_namespace'].folders.first.files.size
|
44
44
|
end
|
45
45
|
|
46
|
-
should "06 load definitions for
|
46
|
+
should "06 load definitions for all resources" do
|
47
47
|
assert Impromptu.root_resource.child?(:Framework)
|
48
48
|
assert Impromptu.root_resource.child(:Framework).child?(:Extensions)
|
49
49
|
assert Impromptu.root_resource.child(:Framework).child(:Extensions).child?(:Blog)
|
50
50
|
assert Impromptu.root_resource.child(:Framework).child?(:Klass)
|
51
|
+
assert Impromptu.root_resource.child(:Framework).child?(:SubKlass)
|
51
52
|
assert Impromptu.root_resource.child(:Framework).child?(:Klass2)
|
52
53
|
assert Impromptu.root_resource.child(:Framework).child?(:Preload)
|
53
54
|
assert Impromptu.root_resource.child?(:Load)
|
@@ -65,6 +66,7 @@ class TestIntegration < Test::Unit::TestCase
|
|
65
66
|
assert_equal false, Impromptu.root_resource.child(:Framework).child(:Extensions).namespace?
|
66
67
|
assert_equal false, Impromptu.root_resource.child(:Framework).child(:Extensions).child(:Blog).namespace?
|
67
68
|
assert_equal false, Impromptu.root_resource.child(:Framework).child(:Klass).namespace?
|
69
|
+
assert_equal false, Impromptu.root_resource.child(:Framework).child(:SubKlass).namespace?
|
68
70
|
assert_equal false, Impromptu.root_resource.child(:Framework).child(:Klass2).namespace?
|
69
71
|
assert_equal false, Impromptu.root_resource.child(:Load).namespace?
|
70
72
|
assert_equal false, Impromptu.root_resource.child(:OtherName).namespace?
|
@@ -81,6 +83,7 @@ class TestIntegration < Test::Unit::TestCase
|
|
81
83
|
assert_equal false, Impromptu.root_resource.child(:'Framework::Extensions').loaded?
|
82
84
|
assert_equal false, Impromptu.root_resource.child(:'Framework::Extensions::Blog').loaded?
|
83
85
|
assert_equal false, Impromptu.root_resource.child(:'Framework::Klass').loaded?
|
86
|
+
assert_equal false, Impromptu.root_resource.child(:'Framework::SubKlass').loaded?
|
84
87
|
assert_equal false, Impromptu.root_resource.child(:'Framework::Klass2').loaded?
|
85
88
|
assert_equal false, Impromptu.root_resource.child(:'Load').loaded?
|
86
89
|
assert_equal false, Impromptu.root_resource.child(:'OtherName').loaded?
|
@@ -101,6 +104,7 @@ class TestIntegration < Test::Unit::TestCase
|
|
101
104
|
assert_equal 1, Impromptu.root_resource.child(:'Framework::Extensions').files.size
|
102
105
|
assert_equal 1, Impromptu.root_resource.child(:'Framework::Extensions::Blog').files.size
|
103
106
|
assert_equal 2, Impromptu.root_resource.child(:'Framework::Klass').files.size
|
107
|
+
assert_equal 1, Impromptu.root_resource.child(:'Framework::SubKlass').files.size
|
104
108
|
assert_equal 1, Impromptu.root_resource.child(:'Framework::Klass2').files.size
|
105
109
|
assert_equal 1, Impromptu.root_resource.child(:'Framework::Preload').files.size
|
106
110
|
assert_equal 1, Impromptu.root_resource.child(:'Framework::Klass2').files.size
|
@@ -292,9 +296,10 @@ class TestIntegration < Test::Unit::TestCase
|
|
292
296
|
File.open('test/framework/lib/klass.rb', 'w') do |file|
|
293
297
|
file.write old_klass
|
294
298
|
end
|
299
|
+
sleep 1 # because file mod times are in seconds, delay by 1s so further tests so an updated timestamp
|
295
300
|
end
|
296
301
|
|
297
|
-
should "reload a class definition correctly when a file is changed" do
|
302
|
+
should "reload a class definition correctly when a file is changed" do
|
298
303
|
# update impromptu and test the new klass is loaded
|
299
304
|
assert_respond_to Framework::Klass, :standard_method
|
300
305
|
assert_equal 2, Framework::Klass.overriden_method
|
@@ -303,6 +308,19 @@ class TestIntegration < Test::Unit::TestCase
|
|
303
308
|
assert_equal false, Framework::Klass.respond_to?(:standard_method)
|
304
309
|
assert_equal 2, Framework::Klass.overriden_method
|
305
310
|
end
|
311
|
+
|
312
|
+
should "unload a subclass if a parent class file is updated" do
|
313
|
+
assert_respond_to Framework::SubKlass, :standard_method
|
314
|
+
assert_equal 2, Framework::SubKlass.overriden_method
|
315
|
+
|
316
|
+
Impromptu.update
|
317
|
+
|
318
|
+
assert_equal false, Impromptu.root_resource.child(:'Framework::SubKlass').loaded?
|
319
|
+
Impromptu.root_resource.child(:'Framework::SubKlass').reload
|
320
|
+
assert_respond_to Framework::SubKlass, :new_method
|
321
|
+
assert_equal false, Framework::SubKlass.respond_to?(:standard_method)
|
322
|
+
assert_equal 2, Framework::SubKlass.overriden_method
|
323
|
+
end
|
306
324
|
end
|
307
325
|
|
308
326
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
7
|
+
- 5
|
8
8
|
- 0
|
9
|
-
version: 1.
|
9
|
+
version: 1.5.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Will Cannings
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-23 00:00:00 +11:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- test/framework/folder_namespace/two_names.rb
|
68
68
|
- test/framework/lib/group/klass2.rb
|
69
69
|
- test/framework/lib/klass.rb
|
70
|
+
- test/framework/lib/sub_klass.rb
|
70
71
|
- test/framework/other/also.rb
|
71
72
|
- test/framework/other/ignore.rb
|
72
73
|
- test/framework/other/load.rb
|
@@ -132,6 +133,7 @@ test_files:
|
|
132
133
|
- test/framework/folder_namespace/two_names.rb
|
133
134
|
- test/framework/lib/group/klass2.rb
|
134
135
|
- test/framework/lib/klass.rb
|
136
|
+
- test/framework/lib/sub_klass.rb
|
135
137
|
- test/framework/other/also.rb
|
136
138
|
- test/framework/other/ignore.rb
|
137
139
|
- test/framework/other/load.rb
|