alloader 0.0.1 → 0.0.2

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: 561377966982d3f3d26613b3008f56ababdc060d
4
- data.tar.gz: 577f091161a31328f2c003a980dce43521a521e5
3
+ metadata.gz: bdb6d4b6adc7a06a767af158acf3f8cc7c70704f
4
+ data.tar.gz: 8fea0cf16ad6ea4212ae00357a5c968cfb51bfdf
5
5
  SHA512:
6
- metadata.gz: 40478dc26f4d85a66c9db628c0840797655bcef97a1fd64b1c22169fda767907b9adafef59195c68ac0370842ff3d4030bb303917137d20167a1f412f1b1ddf1
7
- data.tar.gz: f3e7d30fbfa9a7e212775717e8c3ef2994d101e775334ffa163065646dd27d1df27d5e828f1d08dbad16bdf525273b32ed13641fcc6e8a1e4900682edc539c7e
6
+ metadata.gz: 5fe161958f3b22c215ac969ca18fff6a8549f4e46ea4073f7986f27caa062c06546ae20447cfd0bd594e6530142586d304bad732c5b02c6283edcdc744e08afc
7
+ data.tar.gz: 07ee8c4f866811816fef435d0c2790fbc3ab279dd5d3e53a27be486c14aaf71e357784599ba24bee2acb8aa4b2a1d2721d1d181ce03f8098f1c605ddbac33102
data/lib/alloader.rb CHANGED
@@ -1,39 +1,47 @@
1
- #require "alloader/version"
1
+ require "alloader/version"
2
2
 
3
3
  module Alloader
4
4
 
5
- def required_from; $0 end
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
- def is_directory(path)
8
- FileTest::directory?(path)
9
- end
20
+ def r
21
+ load caller_head
22
+ end
10
23
 
11
- def filelist_in(dir_path)
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
- files + files_in_dirs
20
- end
26
+ def caller_files
27
+ caller.map { |str| File::expand_path(str.split(":")[0]) }
28
+ end
21
29
 
22
- def require_dir(dirpath, mode = :require)
23
- case mode
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
- def r; load required_from end
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
- module_function :require_dir, :r
42
+ files + files_in_dirs
43
+ end
44
+
45
+ end
38
46
 
39
47
  end
@@ -1,3 +1,3 @@
1
1
  module Alloader
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - marg_do