alloader 0.0.21 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c819276f7b77e911ffba591188388c67c30f250
4
- data.tar.gz: c3ef7bde396442b8f9b5c58d746566529a569669
3
+ metadata.gz: 58275a9343512a6d13789d14ca17d6e8cffcf635
4
+ data.tar.gz: 3c563045a4cce1d35f31b8e1cd136af4bf503e4f
5
5
  SHA512:
6
- metadata.gz: 5327b3176507f3eec07b620910bcf3695bb5e6b0b0f55758b5d775f5c42c8687c17af30d79fcd30ab99fa79f8a12d39623e5945ecbf0d640b4c13dac28fc05aa
7
- data.tar.gz: e0ac27dc2dea0ede45b0fc100690ca8b9ff1925d0336587b7951301a16b8360de99d2f2ab680fe94f6cacf92dfd6bf6e912104c68bbd5165979a8933e94df58c
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 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_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 r
21
- load caller_head
11
+ def require_dir(dirpath)
12
+ require_filepaths(filepaths_in_dir(dirpath))
22
13
  end
23
14
 
24
15
  private
25
16
 
26
- def caller_files
27
- caller.map { |str| File::expand_path(str.split(":")[0]) }
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 caller_head
31
- caller_files[-1]
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
- 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) }
51
+ # ----------------------------------------
41
52
 
42
- files + files_in_dirs
53
+ def filter(pred, lst)
54
+ lst.select { |itm| pred.(itm) }
43
55
  end
44
56
 
45
57
  end
@@ -1,3 +1,3 @@
1
1
  module Alloader
2
- VERSION = "0.0.21"
2
+ VERSION = "0.0.22"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - marg_do