alloader 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/lib/alloader.rb +35 -27
- data/lib/alloader/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdb6d4b6adc7a06a767af158acf3f8cc7c70704f
|
4
|
+
data.tar.gz: 8fea0cf16ad6ea4212ae00357a5c968cfb51bfdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fe161958f3b22c215ac969ca18fff6a8549f4e46ea4073f7986f27caa062c06546ae20447cfd0bd594e6530142586d304bad732c5b02c6283edcdc744e08afc
|
7
|
+
data.tar.gz: 07ee8c4f866811816fef435d0c2790fbc3ab279dd5d3e53a27be486c14aaf71e357784599ba24bee2acb8aa4b2a1d2721d1d181ce03f8098f1c605ddbac33102
|
data/lib/alloader.rb
CHANGED
@@ -1,39 +1,47 @@
|
|
1
|
-
|
1
|
+
require "alloader/version"
|
2
2
|
|
3
3
|
module Alloader
|
4
4
|
|
5
|
-
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def require_all(dirpath, mode = :require)
|
8
|
+
case mode
|
9
|
+
when :require
|
10
|
+
filelist_in(dirpath).each do |f|
|
11
|
+
require f
|
12
|
+
end
|
13
|
+
when :load
|
14
|
+
filelist(dirpath).each do |f|
|
15
|
+
load f
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
6
19
|
|
7
|
-
|
8
|
-
|
9
|
-
|
20
|
+
def r
|
21
|
+
load caller_head
|
22
|
+
end
|
10
23
|
|
11
|
-
|
12
|
-
list = (Dir::entries(dir_path) - [".", "..", required_from]).map {|path|
|
13
|
-
File::expand_path(dir_path) + "/" + path
|
14
|
-
}
|
15
|
-
dirs = list.select { |x| FileTest::directory?(x) }
|
16
|
-
files = list - dirs
|
17
|
-
files_in_dirs = dirs.inject([]) { |acc, dir| acc + filelist_in(dir) }
|
24
|
+
private
|
18
25
|
|
19
|
-
|
20
|
-
|
26
|
+
def caller_files
|
27
|
+
caller.map { |str| File::expand_path(str.split(":")[0]) }
|
28
|
+
end
|
21
29
|
|
22
|
-
|
23
|
-
|
24
|
-
when :require
|
25
|
-
filelist_in(dirpath).each do |path|
|
26
|
-
require path
|
27
|
-
end
|
28
|
-
when :load
|
29
|
-
filelist_in(dirpath).each do |path|
|
30
|
-
load path
|
31
|
-
end
|
30
|
+
def caller_head
|
31
|
+
caller_files[-1]
|
32
32
|
end
|
33
|
-
end
|
34
33
|
|
35
|
-
|
34
|
+
def filelist_in(dir_path)
|
35
|
+
list = (Dir::entries(dir_path) - [".", "..", $0]).map {|path|
|
36
|
+
File::expand_path(dir_path) + "/" + path
|
37
|
+
} - caller_files
|
38
|
+
dirs = list.select { |x| FileTest::directory?(x) }
|
39
|
+
files = list - dirs
|
40
|
+
files_in_dirs = dirs.inject([]) { |acc, dir| acc + filelist_in(dir) }
|
36
41
|
|
37
|
-
|
42
|
+
files + files_in_dirs
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
38
46
|
|
39
47
|
end
|
data/lib/alloader/version.rb
CHANGED