require_module 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 +4 -4
- data/Gemfile +8 -2
- data/lib/require_module.rb +3 -2
- data/require_module.gemspec +1 -1
- data/spec/require_module_spec.rb +83 -29
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5492d76df85e6cc8e6b6f1bef49db9d6bd67190edbf0b2c784cf902bda17ba0
|
4
|
+
data.tar.gz: 6fe79ec0348c9f2f8c0459da69ea2d88d55276c38621410ade8407a8617138e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eaf83ad94c4eb0a3c5a51ec96651c0b6425b0b4122ebcf96ac9269fc83841d7e6cef52de7f39ad29ff184111a973f1ec55e6a70a0c119f1049a26323999a49d
|
7
|
+
data.tar.gz: e33c2fecf8f4413a700ea0b6389a993925d118b946a42f02735921129c41b944d413600334f560430f0c04ca81c74fb462552d7a894413b456af17cae7993758
|
data/Gemfile
CHANGED
data/lib/require_module.rb
CHANGED
@@ -16,8 +16,9 @@ module RequireModule
|
|
16
16
|
# require_module('/home/user/rubyapp/lib', cache: false) # returns #<Module:0000012312>
|
17
17
|
# require_module('/home/user/rubyapp/lib') # returns :HomeUserRubyappLib
|
18
18
|
def require_module(fullpath, cache: true)
|
19
|
-
|
20
|
-
|
19
|
+
path = fullpath.to_s
|
20
|
+
with_ext = add_ext(path)
|
21
|
+
without_ext = rem_ext(path)
|
21
22
|
|
22
23
|
if cache
|
23
24
|
constant_name =
|
data/require_module.gemspec
CHANGED
data/spec/require_module_spec.rb
CHANGED
@@ -11,47 +11,101 @@ describe 'require_module_relative' do
|
|
11
11
|
unload_all_matching(/FixturesSomeLib/)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
context 'require_module_relative' do
|
15
|
+
it 'without ext' do
|
16
|
+
mod = require_module_relative './fixtures/some_lib'
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
expect(mod.inspect).to end_with 'FixturesSomeLib'
|
19
|
+
expect(mod.some_fn).to eq 'some_val'
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
it 'with ext' do
|
23
|
+
mod = require_module_relative './fixtures/some_lib.rb'
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
expect(mod.inspect).to end_with 'FixturesSomeLib'
|
26
|
+
expect(mod.some_fn).to eq 'some_val'
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
it 'pathname without ext' do
|
30
|
+
mod = require_module_relative(Pathname.new('./fixtures/some_lib'))
|
31
|
+
|
32
|
+
expect(mod.inspect).to end_with 'FixturesSomeLib'
|
33
|
+
expect(mod.some_fn).to eq 'some_val'
|
34
|
+
end
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
mod2 = require_module_relative './fixtures/some_lib'
|
36
|
+
it 'pathname with ext' do
|
37
|
+
mod = require_module_relative(Pathname.new('./fixtures/some_lib.rb'))
|
37
38
|
|
38
|
-
|
39
|
-
|
39
|
+
expect(mod.inspect).to end_with 'FixturesSomeLib'
|
40
|
+
expect(mod.some_fn).to eq 'some_val'
|
41
|
+
end
|
40
42
|
|
41
|
-
|
43
|
+
it "raises NameError if dependencies can't be resolved" do
|
44
|
+
expect do
|
45
|
+
require_module_relative './unresolveable'
|
46
|
+
end.to raise_error(LoadError)
|
47
|
+
end
|
42
48
|
end
|
43
49
|
|
44
|
-
|
45
|
-
|
50
|
+
context 'require_module' do
|
51
|
+
it 'without ext' do
|
52
|
+
mod = require_module(File.dirname(__FILE__) + '/fixtures/some_lib')
|
53
|
+
|
54
|
+
expect(mod.inspect).to end_with 'FixturesSomeLib'
|
55
|
+
expect(mod.some_fn).to eq 'some_val'
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'with ext' do
|
59
|
+
mod = require_module(File.dirname(__FILE__) + '/fixtures/some_lib.rb')
|
60
|
+
|
61
|
+
expect(mod.inspect).to end_with 'FixturesSomeLib'
|
62
|
+
expect(mod.some_fn).to eq 'some_val'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'pathname without ext' do
|
66
|
+
mod = require_module(Pathname.new(File.dirname(__FILE__) + '/fixtures/some_lib'))
|
46
67
|
|
47
|
-
|
48
|
-
|
68
|
+
expect(mod.inspect).to end_with 'FixturesSomeLib'
|
69
|
+
expect(mod.some_fn).to eq 'some_val'
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'pathname with ext' do
|
73
|
+
mod = require_module(Pathname.new(File.dirname(__FILE__) + '/fixtures/some_lib.rb'))
|
74
|
+
|
75
|
+
expect(mod.inspect).to end_with 'FixturesSomeLib'
|
76
|
+
expect(mod.some_fn).to eq 'some_val'
|
77
|
+
end
|
78
|
+
|
79
|
+
it "raises NameError if dependencies can't be resolved" do
|
80
|
+
expect do
|
81
|
+
require_module './unresolveable'
|
82
|
+
end.to raise_error(LoadError)
|
83
|
+
end
|
49
84
|
end
|
50
85
|
|
51
|
-
|
52
|
-
|
86
|
+
context 'test cache' do
|
87
|
+
it 'test with cache' do
|
88
|
+
mod = require_module_relative './fixtures/some_lib'
|
89
|
+
mod2 = require_module_relative './fixtures/some_lib'
|
90
|
+
|
91
|
+
expect(mod.inspect).to end_with 'FixturesSomeLib'
|
92
|
+
expect(mod2.inspect).to end_with 'FixturesSomeLib'
|
93
|
+
|
94
|
+
expect(mod <=> mod2).to eq 0
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'test without cache' do
|
98
|
+
mod = require_module_relative('./fixtures/some_lib.rb', cache: false)
|
99
|
+
|
100
|
+
expect(mod.inspect).to start_with '#<Module:'
|
101
|
+
expect(mod.some_fn).to eq 'some_val'
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'test without cache and ext' do
|
105
|
+
mod = require_module_relative('./fixtures/some_lib', cache: false)
|
53
106
|
|
54
|
-
|
55
|
-
|
107
|
+
expect(mod.inspect).to start_with '#<Module:'
|
108
|
+
expect(mod.some_fn).to eq 'some_val'
|
109
|
+
end
|
56
110
|
end
|
57
111
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: require_module
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Homa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: melgaardbjorn@gmail.com
|