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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88047665a7fc66a53c7829886ac80d920f16508c
4
- data.tar.gz: b43cf90d9376c24bc6db227b4957ee68a96358df
3
+ metadata.gz: 20cb351318bcb6d21e1f084e93e447206560a1d2
4
+ data.tar.gz: b1021431be32b4569b5b5145e4966cc80f4363ac
5
5
  SHA512:
6
- metadata.gz: 90b7dc3efac44574637277def4d3f616fe4b6698adb82c3591c3c4fd280d87009a96acc70465593adfb84b5c7ea263475d2cd5a9a37aaedf9a35767b74499a71
7
- data.tar.gz: c9c2a6d93064fd0f2881e8d17cc80f91b18aa573939ef35dd0fd74d5899eebe578ff239d43c645d5b5dd6462b279aad619e2807e740a82edc00eec670d9c2ccb
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
- require path
9
- const_get(cname)
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
@@ -1,3 +1,3 @@
1
1
  module Autoloading
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -24,9 +24,27 @@ describe Autoloading do
24
24
  end
25
25
  FILE
26
26
 
27
- $: << test_file_root.to_s
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
 
@@ -1,17 +1,17 @@
1
1
  require 'fileutils'
2
2
  module TestFiles
3
- def test_file_root
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 = test_file_root.join(name)
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(test_file_root.to_s)
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.1
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-03-23 00:00:00.000000000 Z
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.1
79
+ rubygems_version: 2.2.2
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: Autoload Ruby classes or modules