autoload 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.index +44 -0
- data/.yardopts +7 -0
- data/HISTORY.md +11 -0
- data/Index.yml +36 -0
- data/LICENSE.txt +23 -0
- data/README.md +41 -0
- data/Setup.rb +1340 -0
- data/demo/01_autoload.md +16 -0
- data/demo/applique/ae.rb +2 -0
- data/demo/applique/main.rb +6 -0
- data/demo/fixture/tryme.rb +2 -0
- data/lib/autoload.rb +46 -0
- metadata +95 -0
data/demo/01_autoload.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Autoload
|
2
|
+
|
3
|
+
Autoload is a very simple library. The programmer specifies the files to be required
|
4
|
+
when an unknown constant is first used, and Autoload will automatically load it
|
5
|
+
and return the newly found constant.
|
6
|
+
|
7
|
+
autoload 'TryMe', 'tryme'
|
8
|
+
|
9
|
+
Even though we haven't yet required "tryme", we should have no problem
|
10
|
+
access the the TryMe constant which is defined in this file.
|
11
|
+
|
12
|
+
TryMe #=> true
|
13
|
+
|
14
|
+
That's pretty much it. The other point is that this autload can be used within
|
15
|
+
a module for constants relative to its namespace.
|
16
|
+
|
data/demo/applique/ae.rb
ADDED
data/lib/autoload.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
$AUTOLOAD = Hash.new{ |h, k| h[k] = [] }
|
2
|
+
|
3
|
+
#
|
4
|
+
#
|
5
|
+
#
|
6
|
+
def self.autoload(name, path)
|
7
|
+
$AUTOLOAD[name.to_sym] << path
|
8
|
+
end
|
9
|
+
|
10
|
+
class Module
|
11
|
+
#
|
12
|
+
#
|
13
|
+
#
|
14
|
+
def self.autoload(subname, path)
|
15
|
+
$AUTOLOAD["#{name}::#{subname}".to_sym] << path
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module Kernel
|
20
|
+
#
|
21
|
+
# Note: I am not so certain the instance level method is a good idea.
|
22
|
+
# The end used can just as easily and more cleary use `self.class.autoload`
|
23
|
+
# to do it themselves.
|
24
|
+
#
|
25
|
+
def autoload(subname, path)
|
26
|
+
$AUTOLOAD["#{self.class.name}::#{subname}".to_sym] << path
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Object
|
31
|
+
#
|
32
|
+
#
|
33
|
+
#
|
34
|
+
def self.const_missing(name)
|
35
|
+
if paths = $AUTOLOAD.delete(name)
|
36
|
+
paths.each do |path|
|
37
|
+
require(path)
|
38
|
+
end
|
39
|
+
super(name) unless const_defined?(name)
|
40
|
+
const_get(name)
|
41
|
+
else
|
42
|
+
super(name)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: autoload
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- trans
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: qed
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ae
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Ruby is officially deprecating autoload. Well, some people may prefer
|
47
|
+
to keep it! Moreover, Ruby's implementation has had a bug in it for-like-ever. This
|
48
|
+
gem fixes that problem too.
|
49
|
+
email:
|
50
|
+
- transfire@gmail.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files:
|
54
|
+
- LICENSE.txt
|
55
|
+
- HISTORY.md
|
56
|
+
- README.md
|
57
|
+
files:
|
58
|
+
- .index
|
59
|
+
- .yardopts
|
60
|
+
- demo/applique/main.rb
|
61
|
+
- demo/applique/ae.rb
|
62
|
+
- demo/01_autoload.md
|
63
|
+
- demo/fixture/tryme.rb
|
64
|
+
- lib/autoload.rb
|
65
|
+
- LICENSE.txt
|
66
|
+
- Index.yml
|
67
|
+
- HISTORY.md
|
68
|
+
- README.md
|
69
|
+
- Setup.rb
|
70
|
+
homepage: http://dotruby.github.com
|
71
|
+
licenses:
|
72
|
+
- BSD-2-Clause
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.8.23
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: What Ruby does but how Ruby should do it.
|
95
|
+
test_files: []
|