dohroot 0.1.4 → 0.1.5

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: a628c800cf04d1142066cddb9732eeed0e8caafd
4
- data.tar.gz: a789a6841767f6f37cc00a02247748d7f1e96249
3
+ metadata.gz: 58d1c31025738476a4809c3f8cbba08b68f78cad
4
+ data.tar.gz: 838168da9351a35477c0abb82306139079f0dc68
5
5
  SHA512:
6
- metadata.gz: ba38e9d5becf4d13984ad88fa16ab2374f785f86962e717f38d47c0c149dcdfb453da2b770d2ac0be29c97d9f03bd2ffbb5d9c9d8cceb0f2ea1ff3e0a6543486
7
- data.tar.gz: 567ed8a2969ce33d60731188da0845e1a6aeee81f5a511f4f9c7bf6ea882d5c3fda925f52ffefb4157dd6b2561c26d79d838477deee6ff4bf2a6d56fb8a5c2cd
6
+ metadata.gz: b3fb9662b9bd3b0d14ed9f70e507cdfbaa421f625944dfc07f240777c60625dccade6c4a1930dac3359ba11e9e0db0e7aaca6531e54a342c67fc4f9d45310a17
7
+ data.tar.gz: 7e5c37abc0cab05e4636132020eeb5324f3f755c5a3e50ac62e60d774549a5f9b930acaa8a01caeea6f5ec48cc0f1d955fcdaee27f3b884949ce1b92f698dd5e
@@ -0,0 +1,43 @@
1
+ require 'dohroot/findup'
2
+
3
+ module Doh
4
+ extend self
5
+
6
+ def root
7
+ @root
8
+ end
9
+
10
+ def root=(directory)
11
+ @root = directory
12
+ libdir = File.join(@root, 'lib')
13
+ $LOAD_PATH.push(libdir) if libdir && !$LOAD_PATH.include?(libdir)
14
+ end
15
+
16
+ def find_root(start_directory, filename = 'dohroot', max_tries = 20)
17
+ rootfile = Doh.findup(start_directory, filename, max_tries)
18
+ if rootfile
19
+ Doh.root = File.dirname(rootfile)
20
+ end
21
+ end
22
+
23
+ def find_root_from_file(filepath = nil)
24
+ Doh.find_root(File.dirname(filepath || caller[0]))
25
+ end
26
+
27
+ def find_root_from_path(path)
28
+ if File.directory?(path)
29
+ Doh.find_root(path)
30
+ else
31
+ Doh.find_root(File.dirname(path))
32
+ end
33
+ end
34
+
35
+ def find_root_from_prog
36
+ Doh.find_root(File.dirname($PROGRAM_NAME))
37
+ end
38
+
39
+ def find_root_from_pwd
40
+ Doh.find_root(Dir.pwd)
41
+ end
42
+
43
+ end
@@ -0,0 +1,38 @@
1
+ require 'dohroot/main'
2
+
3
+ module Doh
4
+ extend self
5
+
6
+ def use_pkg(init_file, *name_list)
7
+ if name_list.empty?
8
+ Dir.glob(File.join(Doh.root, 'pkg/*/')).each do |rootdir|
9
+ name_list << File.basename(rootdir)
10
+ end
11
+ end
12
+
13
+ @pkg_used ||= []
14
+ retval = false
15
+ name_list.each do |name|
16
+ next if @pkg_used.include?(name)
17
+ retval = true
18
+ @pkg_used << name
19
+ use_one_pkg(init_file, name)
20
+ end
21
+ retval
22
+ end
23
+
24
+ private
25
+
26
+ def use_one_pkg(init_file, name)
27
+ libdir = File.join(Doh.root, "pkg/#{name}/lib")
28
+ unless $LOAD_PATH.include?(libdir)
29
+ $LOAD_PATH << libdir
30
+ end
31
+
32
+ init_path = File.join(Doh.root, "pkg/#{name}/#{init_file}.rb")
33
+ if File.exist?(init_path)
34
+ require init_path
35
+ end
36
+ end
37
+
38
+ end
data/lib/dohroot.rb CHANGED
@@ -1,75 +1,2 @@
1
- require 'dohroot/findup'
2
-
3
- module Doh
4
- extend self
5
-
6
- class DohRootNotFoundException < Exception
7
- end
8
-
9
- def root
10
- @root
11
- end
12
-
13
- def root=(directory)
14
- @root = directory
15
- libdir = File.join(@root, 'lib')
16
- $LOAD_PATH.push(libdir) if libdir && !$LOAD_PATH.include?(libdir)
17
- end
18
-
19
- def find_root(start_directory, filename = 'dohroot', max_tries = 20)
20
- rootfile = Doh.findup(start_directory, filename, max_tries)
21
- if rootfile
22
- Doh.root = File.dirname(rootfile)
23
- end
24
- end
25
-
26
- def find_root_from_file(filepath = nil)
27
- Doh.find_root(File.dirname(filepath || caller[0]))
28
- end
29
-
30
- def find_root_from_path(path)
31
- if File.directory?(path)
32
- Doh.find_root(path)
33
- else
34
- Doh.find_root(File.dirname(path))
35
- end
36
- end
37
-
38
- def find_root_from_prog
39
- Doh.find_root(File.dirname($PROGRAM_NAME))
40
- end
41
-
42
- def find_root_from_pwd
43
- Doh.find_root(Dir.pwd)
44
- end
45
-
46
- def use_pkg(init_file, *name_list)
47
- if name_list.empty?
48
- Dir.glob(File.join(Doh.root, 'pkg/*/')).each do |rootdir|
49
- name_list << File.basename(rootdir)
50
- end
51
- end
52
-
53
- @pkg_used ||= []
54
- name_list.each do |name|
55
- next if @pkg_used.include?(name)
56
- @pkg_used << name
57
- use_one_pkg(init_file, name)
58
- end
59
- end
60
-
61
- private
62
-
63
- def use_one_pkg(init_file, name)
64
- libdir = File.join(Doh.root, "pkg/#{name}/lib")
65
- unless $LOAD_PATH.include?(libdir)
66
- $LOAD_PATH << libdir
67
- end
68
-
69
- init_path = File.join(Doh.root, "pkg/#{name}/#{init_file}.rb")
70
- if File.exist?(init_path)
71
- require init_path
72
- end
73
- end
74
-
75
- end # module Doh
1
+ require 'dohroot/main'
2
+ require 'dohroot/pkg'
data/test/add_lib.rb ADDED
@@ -0,0 +1,2 @@
1
+ libdir = File.expand_path(File.join(__dir__, '../lib'))
2
+ $LOAD_PATH.push(libdir) if libdir && !$LOAD_PATH.include?(libdir)
data/test/pkg.dt.rb ADDED
@@ -0,0 +1,15 @@
1
+ require_relative 'add_lib'
2
+ require 'dohroot/pkg'
3
+ require 'minitest/autorun'
4
+
5
+ module Doh
6
+
7
+ class Test_pkg < MiniTest::Unit::TestCase
8
+ def test_use_more_than_once
9
+ Doh.root = File.join(__dir__, 'fake_pkg_root')
10
+ assert(Doh.use_pkg(:none, 'some'))
11
+ assert(!Doh.use_pkg(:none, 'some'))
12
+ end
13
+ end
14
+
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dohroot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Makani Mason
@@ -21,7 +21,11 @@ extra_rdoc_files:
21
21
  files:
22
22
  - lib/dohroot.rb
23
23
  - lib/dohroot/findup.rb
24
+ - lib/dohroot/main.rb
24
25
  - lib/dohroot/options.rb
26
+ - lib/dohroot/pkg.rb
27
+ - test/add_lib.rb
28
+ - test/pkg.dt.rb
25
29
  - MIT-LICENSE
26
30
  homepage: https://github.com/atpsoft/dohroot
27
31
  licenses:
@@ -47,4 +51,6 @@ rubygems_version: 2.0.6
47
51
  signing_key:
48
52
  specification_version: 4
49
53
  summary: tiniest root of doh stuff
50
- test_files: []
54
+ test_files:
55
+ - test/add_lib.rb
56
+ - test/pkg.dt.rb