autoloading 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/lib/autoloading.rb +21 -2
- data/lib/autoloading/version.rb +1 -1
- data/test/autoloading_spec.rb +19 -1
- data/test/support/test_files.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20cb351318bcb6d21e1f084e93e447206560a1d2
|
4
|
+
data.tar.gz: b1021431be32b4569b5b5145e4966cc80f4363ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79892a3428c6ea54c664f9e48004973091ea7042d3ff0783a1d11b193dabb59c10c5c10eb9e74cd2513b5698da6a2ba9e3d12d010cf8a5d8fae6a901e76f27a2
|
7
|
+
data.tar.gz: f3475cf5f2939abdd26dcb8b0639aa70681a0a555ac93ec5d513706a0f6c21f238d61c027dec0f98a3d46c02039af7eec174ed540f0c30290c46a06caa33cb7b
|
data/lib/autoloading.rb
CHANGED
@@ -5,8 +5,22 @@ module Autoloading
|
|
5
5
|
prefix = underscore(self.name.to_s)
|
6
6
|
filename = underscore(cname.to_s)
|
7
7
|
path = "#{prefix}/#{filename}"
|
8
|
-
|
9
|
-
|
8
|
+
begin
|
9
|
+
require path
|
10
|
+
return const_get(cname)
|
11
|
+
rescue LoadError
|
12
|
+
tried_requires = [path]
|
13
|
+
(@autoload_without_namespacing || []).each do |dirname|
|
14
|
+
path = "#{prefix}/#{dirname}/#{filename}"
|
15
|
+
tried_requires << path
|
16
|
+
begin
|
17
|
+
require path
|
18
|
+
return const_get(cname)
|
19
|
+
rescue LoadError
|
20
|
+
end
|
21
|
+
end
|
22
|
+
raise LoadError, "cannot load such file -- #{tried_requires.join(', ')}"
|
23
|
+
end
|
10
24
|
end
|
11
25
|
|
12
26
|
# Based on ActiveSupport, removed inflections.
|
@@ -19,4 +33,9 @@ module Autoloading
|
|
19
33
|
word.downcase!
|
20
34
|
word
|
21
35
|
end
|
36
|
+
|
37
|
+
def autoload_without_namespacing(*dirnames)
|
38
|
+
@autoload_without_namespacing ||= []
|
39
|
+
@autoload_without_namespacing.concat(dirnames)
|
40
|
+
end
|
22
41
|
end
|
data/lib/autoloading/version.rb
CHANGED
data/test/autoloading_spec.rb
CHANGED
@@ -24,9 +24,27 @@ describe Autoloading do
|
|
24
24
|
end
|
25
25
|
FILE
|
26
26
|
|
27
|
-
$: <<
|
27
|
+
$: << temp_file_root.to_s
|
28
28
|
require 'hello'
|
29
29
|
Hello::Kitty
|
30
30
|
end
|
31
|
+
|
32
|
+
it "can autoload without namespacing" do
|
33
|
+
create_test_file "zoo.rb", <<-FILE
|
34
|
+
module Zoo
|
35
|
+
extend Autoloading
|
36
|
+
autoload_without_namespacing "animals"
|
37
|
+
end
|
38
|
+
FILE
|
39
|
+
|
40
|
+
create_test_file "zoo/animals/kitty.rb", <<-FILE
|
41
|
+
module Zoo::Kitty
|
42
|
+
end
|
43
|
+
FILE
|
44
|
+
|
45
|
+
$: << temp_file_root.to_s
|
46
|
+
require 'zoo'
|
47
|
+
Zoo::Kitty
|
48
|
+
end
|
31
49
|
end
|
32
50
|
|
data/test/support/test_files.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
module TestFiles
|
3
|
-
def
|
3
|
+
def temp_file_root
|
4
4
|
Pathname.new(File.dirname(__FILE__)).join('..', '..', 'tmp', 'file_tests')
|
5
5
|
end
|
6
6
|
|
7
7
|
def create_test_file(name, contents)
|
8
|
-
path =
|
8
|
+
path = temp_file_root.join(name)
|
9
9
|
FileUtils.mkdir_p(File.dirname(path))
|
10
10
|
File.open(path, 'w') { |f| f.write(contents) }
|
11
11
|
end
|
12
12
|
|
13
13
|
def delete_test_files
|
14
|
-
FileUtils.rm_rf(
|
14
|
+
FileUtils.rm_rf(temp_file_root.to_s)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autoloading
|
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
|
- Levente Bagi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
78
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.2.
|
79
|
+
rubygems_version: 2.2.2
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: Autoload Ruby classes or modules
|