alloader 0.0.21 → 0.0.22
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 +37 -25
- 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: 58275a9343512a6d13789d14ca17d6e8cffcf635
|
4
|
+
data.tar.gz: 3c563045a4cce1d35f31b8e1cd136af4bf503e4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5728c17564433f83d0d20f785636402af1864fa787c4dbecff83cfb2d824e0a9330af02c88dbefc820c28ec5f9c3a2381d40fa60c4c3ca8a44373f7b2494c455
|
7
|
+
data.tar.gz: 7d8509cba63e16c09e852786a21133cf375c54cefb5245879d87657a042c636f57816e24a64d7496ea33abab76a07994eaa0a09f247170349bf693ed033280ba
|
data/lib/alloader.rb
CHANGED
@@ -4,42 +4,54 @@ module Alloader
|
|
4
4
|
|
5
5
|
class << self
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
when :require
|
10
|
-
filelist_in(dirpath).each do |f|
|
11
|
-
require f
|
12
|
-
end
|
13
|
-
when :load
|
14
|
-
filelist_in(dirpath).each do |f|
|
15
|
-
load f
|
16
|
-
end
|
17
|
-
end
|
7
|
+
def load_dir(dirpath)
|
8
|
+
load_filepaths(filepaths_in_dir(dirpath))
|
18
9
|
end
|
19
10
|
|
20
|
-
def
|
21
|
-
|
11
|
+
def require_dir(dirpath)
|
12
|
+
require_filepaths(filepaths_in_dir(dirpath))
|
22
13
|
end
|
23
14
|
|
24
15
|
private
|
25
16
|
|
26
|
-
|
27
|
-
|
17
|
+
# ----------------------------------------
|
18
|
+
|
19
|
+
def is_dir(path)
|
20
|
+
FileTest::directory?(path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def filepaths_in_dir(dirpath)
|
24
|
+
filelist = (Dir::entries(dirpath) - [".", ".."]).map { |file|
|
25
|
+
File::expand_path(dirpath + "/" + file)
|
26
|
+
}
|
27
|
+
dirpaths = filter(method(:is_dir), filelist)
|
28
|
+
filepaths_in_dirpaths = dirpaths.inject([]) { |acc, dirpath|
|
29
|
+
acc + filepaths_in_dir(dirpath)
|
30
|
+
}
|
31
|
+
|
32
|
+
filelist - dirpaths + filepaths_in_dirpaths
|
28
33
|
end
|
29
34
|
|
30
|
-
def
|
31
|
-
|
35
|
+
def require_filepaths(filepaths)
|
36
|
+
result = {}
|
37
|
+
filepaths.each do |filepath|
|
38
|
+
result[filepath] = require filepath
|
39
|
+
end
|
40
|
+
result
|
41
|
+
end
|
42
|
+
|
43
|
+
def load_filepaths(filepaths)
|
44
|
+
result = {}
|
45
|
+
filepaths.each do |filepath|
|
46
|
+
result[filepath] = load filepath
|
47
|
+
end
|
48
|
+
result
|
32
49
|
end
|
33
50
|
|
34
|
-
|
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) }
|
51
|
+
# ----------------------------------------
|
41
52
|
|
42
|
-
|
53
|
+
def filter(pred, lst)
|
54
|
+
lst.select { |itm| pred.(itm) }
|
43
55
|
end
|
44
56
|
|
45
57
|
end
|
data/lib/alloader/version.rb
CHANGED