class_loader 3.0.3 → 3.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/class_loader/class_loader.rb +9 -8
- data/lib/class_loader/watcher.rb +1 -0
- data/readme.md +15 -7
- metadata +2 -2
@@ -72,20 +72,21 @@ module ClassLoader
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
#
|
76
|
-
|
77
|
-
def preload path
|
75
|
+
# Eagerly load all classes in paths.
|
76
|
+
def preload *paths
|
78
77
|
monitor.synchronize do
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
paths.each do |path|
|
79
|
+
Dir.glob("#{path}/**/*.rb").each do |class_path|
|
80
|
+
class_file_name = class_path.sub("#{path}/", '').sub(/\.rb$/, '')
|
81
|
+
require class_file_name
|
82
|
+
end
|
82
83
|
end
|
83
84
|
end
|
84
85
|
end
|
85
86
|
|
86
87
|
# Watch and reload files.
|
87
|
-
def watch
|
88
|
-
watcher.paths << path
|
88
|
+
def watch *paths
|
89
|
+
paths.each{|path| watcher.paths << path}
|
89
90
|
watcher.start
|
90
91
|
end
|
91
92
|
|
data/lib/class_loader/watcher.rb
CHANGED
data/readme.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# ClassLoader automatically finds, loads and reloads classes
|
2
2
|
|
3
3
|
Suppose there's following directory structure:
|
4
4
|
|
@@ -8,7 +8,7 @@ Suppose there's following directory structure:
|
|
8
8
|
/another_class.rb # class SomeNamespace:AnotherClass; end
|
9
9
|
/some_namespace.rb # module SomeNamespace; end
|
10
10
|
|
11
|
-
All these classes will be loaded automatically
|
11
|
+
All these classes will be loaded automatically:
|
12
12
|
|
13
13
|
``` ruby
|
14
14
|
require 'class_loader'
|
@@ -17,17 +17,13 @@ SomeClass
|
|
17
17
|
SomeNamespace::AnotherClass
|
18
18
|
```
|
19
19
|
|
20
|
-
No need for require
|
20
|
+
No need for `require` or `autoload`:
|
21
21
|
|
22
22
|
``` ruby
|
23
23
|
require 'some_class'
|
24
24
|
require 'some_namespace'
|
25
25
|
require 'some_namespace/another_class'
|
26
|
-
```
|
27
|
-
|
28
|
-
or autoload:
|
29
26
|
|
30
|
-
``` ruby
|
31
27
|
autoload :SomeClass, 'some_class'
|
32
28
|
autoload :SomeNamespace, 'some_namespace'
|
33
29
|
module SomeNamespace
|
@@ -35,6 +31,18 @@ module SomeNamespace
|
|
35
31
|
end
|
36
32
|
```
|
37
33
|
|
34
|
+
You can also tell it to watch and reload changes:
|
35
|
+
|
36
|
+
``` ruby
|
37
|
+
ClassLoader.watch 'my_app/lib'
|
38
|
+
```
|
39
|
+
|
40
|
+
Or preload classes eagerly:
|
41
|
+
|
42
|
+
``` ruby
|
43
|
+
ClassLoader.preload 'my_app/lib'
|
44
|
+
```
|
45
|
+
|
38
46
|
## Installation
|
39
47
|
|
40
48
|
$ gem install class_loader
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: class_loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
12
|
+
date: 2011-10-30 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|