autoloaded 1.7.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +8 -4
- data/.rspec +1 -1
- data/.travis.yml +1 -15
- data/Gemfile +10 -11
- data/Guardfile +22 -21
- data/History.md +16 -40
- data/License.md +1 -1
- data/README.md +69 -79
- data/Rakefile +0 -4
- data/autoloaded.gemspec +37 -41
- data/lib/autoloaded/autoloader.rb +8 -31
- data/lib/autoloaded/deprecation.rb +20 -11
- data/lib/autoloaded/inflection.rb +9 -7
- data/lib/autoloaded/load_pathed_directory.rb +4 -2
- data/lib/autoloaded/specification.rb +0 -2
- data/lib/autoloaded/specifications.rb +10 -16
- data/lib/autoloaded/version.rb +1 -1
- data/lib/autoloaded/warning.rb +44 -26
- data/lib/autoloaded.rb +0 -40
- data/lib/tasks/lib_each.rake +3 -15
- data/lib/tasks/spec.rake +6 -3
- data/spec/autoloaded/autoloader_spec.rb +469 -0
- data/spec/autoloaded/inflection_spec.rb +30 -0
- data/spec/autoloaded/load_pathed_directory_spec.rb +120 -0
- data/spec/autoloaded/specification_spec.rb +98 -0
- data/spec/autoloaded/specifications_spec.rb +191 -0
- data/spec/autoloaded/version_spec.rb +3 -0
- data/spec/autoloaded/warning_spec.rb +115 -0
- data/spec/autoloaded_macro_sharedspec.rb +24 -0
- data/spec/autoloaded_spec.rb +173 -0
- data/spec/fixtures/autoloaded_with_conventional_filename/N-est-ed.rb +1 -0
- data/spec/fixtures/autoloaded_with_conventional_filename/nest_ed.rb +1 -0
- data/spec/fixtures/autoloaded_with_conventional_filename/nested/doubly_nested.rb +9 -0
- data/spec/fixtures/autoloaded_with_conventional_filename/nested.rb +16 -0
- data/spec/fixtures/autoloaded_with_conventional_filename/old_school_autoload.rb +5 -0
- data/spec/fixtures/autoloaded_with_conventional_filename.rb +12 -0
- data/spec/fixtures/autoloaded_with_unconventional_filename/N-est-ed.rb +7 -0
- data/spec/fixtures/autoloaded_with_unconventional_filename/nest_ed.rb +1 -0
- data/spec/fixtures/autoloaded_with_unconventional_filename/old_school_autoload.rb +5 -0
- data/spec/fixtures/autoloaded_with_unconventional_filename.rb +12 -0
- data/spec/fixtures/filenames/AFilename.rb +0 -0
- data/spec/fixtures/filenames/a-file-name.rb +0 -0
- data/spec/fixtures/filenames/a-filename.rb +0 -0
- data/spec/fixtures/filenames/a_file_name.rb +0 -0
- data/spec/fixtures/filenames/a_filename.rb +0 -0
- data/spec/fixtures/filenames/afile-name.rb +0 -0
- data/spec/fixtures/filenames/afile_name.rb +0 -0
- data/spec/fixtures/not_autoloaded/nested.rb +1 -0
- data/spec/fixtures/not_autoloaded/old_school_autoload.rb +5 -0
- data/spec/fixtures/not_autoloaded.rb +5 -0
- data/spec/matchers.rb +85 -0
- data/spec/spec_helper.rb +91 -0
- data/spec/support/util.rb +42 -0
- data/spec/support/without_side_effects.rb +37 -0
- metadata +86 -25
- data/bin/console +0 -10
- data/bin/setup +0 -8
- data/lib/autoloaded/compatibility/refine_and_using.rb +0 -19
- data/lib/autoloaded/constant.rb +0 -94
- data/lib/autoloaded/refine/string/to_source_filename.rb +0 -58
- data/lib/autoloaded/refine/string.rb +0 -20
- data/lib/autoloaded/refine.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 925ea1aba0f2ef88679610b9991b59b47d1624bb
|
4
|
+
data.tar.gz: 9a76651fade295cb47f3aa0bb13d4a1d38da1bb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff3a0b9a5ad7f85e1302b6e3d9b1757e13e2dda0c85feeb8f06184b461773503acb41d5dadb487e4219e4c9a485bfebbf0bc7055c1c9e240a84d00d638fba0de
|
7
|
+
data.tar.gz: 2f438027039fa6e9fc1b23c5b2669864fe5dff3b5ed2a7576495d33f0552a14d8f063b67c8a0295b173001c12ff307ad1fda82f2ff498d10c87cfab47dd902fa
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.travis.yml
CHANGED
@@ -1,27 +1,13 @@
|
|
1
1
|
language: ruby
|
2
2
|
bundler_args: --without debug doc tooling
|
3
3
|
rvm:
|
4
|
+
- 1.9
|
4
5
|
- 2.0
|
5
6
|
- 2.1
|
6
|
-
- 2.2
|
7
|
-
- 2.3
|
8
|
-
- 2.4
|
9
|
-
- 2.5
|
10
|
-
- 2.6
|
11
|
-
- 2.7
|
12
|
-
- 3.0
|
13
7
|
- ruby-head
|
14
8
|
- jruby-head
|
15
|
-
- rbx
|
16
|
-
- rbx-2
|
17
9
|
script: "bundle exec rake test"
|
18
10
|
matrix:
|
19
11
|
allow_failures:
|
20
|
-
- rvm: 1.9
|
21
12
|
- rvm: ruby-head
|
22
13
|
- rvm: jruby-head
|
23
|
-
- rvm: rbx
|
24
|
-
- rvm: rbx-2
|
25
|
-
branches:
|
26
|
-
except:
|
27
|
-
- /^gh-pages.*$/
|
data/Gemfile
CHANGED
@@ -3,23 +3,22 @@ source 'https://rubygems.org'
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :debug do
|
6
|
-
gem 'pry-byebug',
|
7
|
-
|
8
|
-
:mri_22,
|
9
|
-
:mri_23,
|
10
|
-
:mri_24,
|
11
|
-
:mri_25]
|
12
|
-
gem 'pry-debugger', '~> 0', platforms: :mri_19
|
6
|
+
gem 'pry-byebug', '~> 2', platforms: [:mri_20, :mri_21]
|
7
|
+
gem 'pry-debugger', '~> 0', platforms: :mri_19
|
13
8
|
end
|
14
9
|
|
15
10
|
group :doc do
|
16
|
-
gem 'yard',
|
17
|
-
gem 'rdiscount',
|
11
|
+
gem 'yard', '~> 0', require: false
|
12
|
+
gem 'rdiscount', '~> 2', require: false, platforms: :mri
|
13
|
+
end
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem 'codeclimate-test-reporter', '~> 0', require: false
|
18
17
|
end
|
19
18
|
|
20
19
|
group :tooling do
|
21
|
-
gem 'guard-rspec',
|
20
|
+
gem 'guard-rspec', '~> 4', require: false
|
22
21
|
if RUBY_PLATFORM =~ /darwin/i
|
23
|
-
gem 'rb-fsevent',
|
22
|
+
gem 'rb-fsevent', '~> 0', require: false
|
24
23
|
end
|
25
24
|
end
|
data/Guardfile
CHANGED
@@ -1,37 +1,38 @@
|
|
1
|
-
|
1
|
+
interactor :off
|
2
2
|
|
3
3
|
debugger_gem = %w(pry-byebug pry-debugger).detect do |gem|
|
4
4
|
`bundle show #{gem} 2>&1 >/dev/null`
|
5
5
|
$?.success?
|
6
6
|
end
|
7
7
|
debugger_require = debugger_gem ? " --require #{debugger_gem}" : nil
|
8
|
+
guard :rspec, all_after_pass: true,
|
9
|
+
all_on_start: true,
|
10
|
+
cmd: "bundle exec rspec#{debugger_require} --format progress" do
|
11
|
+
# Run the corresponding spec (or all specs) when code changes.
|
12
|
+
watch( %r{^lib/(.+)\.rb$} ) do |match|
|
13
|
+
Dir["spec/#{match[1]}_spec.rb"].first || 'spec'
|
14
|
+
end
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
cmd: "bundle exec rspec --format progress#{debugger_require}" do
|
12
|
-
dsl = Guard::RSpec::Dsl.new(self)
|
13
|
-
rspec, ruby = dsl.rspec, dsl.ruby
|
16
|
+
# Run a spec when it changes.
|
17
|
+
watch %r{^spec/.+_spec\.rb$}
|
14
18
|
|
15
|
-
#
|
16
|
-
watch(
|
17
|
-
watch rspec.spec_helper { rspec.spec_dir }
|
18
|
-
watch rspec.spec_support { rspec.spec_dir }
|
19
|
-
watch(%r{^spec/support}) { rspec.spec_dir } # This should not be necessary.
|
20
|
-
watch rspec.spec_files
|
19
|
+
# Run all specs when a shared spec changes.
|
20
|
+
watch( %r{^spec/.+_sharedspec\.rb$} ) { 'spec' }
|
21
21
|
|
22
22
|
# Run all specs when a matcher changes.
|
23
|
-
watch('spec/matchers.rb') { 'spec' }
|
23
|
+
watch( 'spec/matchers.rb' ) { 'spec' }
|
24
24
|
|
25
|
-
# Run all specs when a
|
26
|
-
watch(%r{^spec
|
25
|
+
# Run all specs when a support file changes.
|
26
|
+
watch( %r{^spec/support} ) { 'spec' }
|
27
27
|
|
28
28
|
# Run all specs when a fixture changes.
|
29
|
-
watch(%r{^spec/fixtures}) {
|
29
|
+
watch( %r{^spec/fixtures} ) { 'spec' }
|
30
30
|
|
31
|
-
# Run all specs when the
|
32
|
-
watch('
|
33
|
-
watch(
|
31
|
+
# Run all specs when the RSpec configuration changes.
|
32
|
+
watch( '.rspec' ) { 'spec' }
|
33
|
+
watch( 'spec/spec_helper.rb' ) { 'spec' }
|
34
34
|
|
35
|
-
#
|
36
|
-
|
35
|
+
# Run all specs when the bundle changes.
|
36
|
+
watch( 'Gemfile.lock' ) { 'spec' }
|
37
|
+
watch( %r{^(.+)\.gemspec$} ) { 'spec' }
|
37
38
|
end
|
data/History.md
CHANGED
@@ -1,49 +1,30 @@
|
|
1
|
-
# Version history for the
|
1
|
+
# Version history for the _Autoloaded_ project
|
2
2
|
|
3
|
-
## <a name="
|
3
|
+
## <a name="v2.0.0"></a>v2.0.0, Sat 12/27/2013
|
4
4
|
|
5
|
-
* Add support for Ruby
|
5
|
+
* Add support for Ruby v1.9.x
|
6
|
+
* Remove deprecated API
|
6
7
|
|
7
|
-
## <a name="v1.
|
8
|
-
|
9
|
-
* Eliminate Ruby warnings about
|
10
|
-
[*Binding#source_location*][Ruby-Core-Binding-source_location] (thanks to
|
11
|
-
[@guss77][GitHub-user-guss77])
|
12
|
-
|
13
|
-
## <a name="v1.5.1"></a>v1.5.1, Wed 10/18/2017
|
14
|
-
|
15
|
-
* Eliminate Ruby warnings about undefined instance variables
|
16
|
-
|
17
|
-
## <a name="v1.5.0"></a>v1.5.0, Wed 2/22/2017
|
18
|
-
|
19
|
-
* Add support for Ruby load paths (`$:`) that contain one or more
|
20
|
-
[*Pathname*][Ruby-Stdlib-Pathname] objects (thanks to
|
21
|
-
[@ekampp][GitHub-user-ekampp])
|
22
|
-
|
23
|
-
## <a name="v1.4.1"></a>v1.4.1, Sat 1/24/2015
|
24
|
-
|
25
|
-
* Don’t warn about a *VERSION* constant presumably loaded by a *.gemspec*
|
26
|
-
|
27
|
-
## <a name="v1.3.0"></a>v1.3.0, Fri 12/26/2014
|
8
|
+
## <a name="v1.3.0"></a>v1.3.0, Fri 12/26/2013
|
28
9
|
|
29
10
|
* Add support for relative class references with a new API
|
30
11
|
|
31
|
-
## <a name="v1.2.0"></a>v1.2.0, Fri 11/28/
|
12
|
+
## <a name="v1.2.0"></a>v1.2.0, Fri 11/28/2013
|
32
13
|
|
33
14
|
* Add support for [JRuby][JRuby] (Ruby v2.x-compatible versions)
|
34
15
|
|
35
|
-
## <a name="v1.1.0"></a>v1.1.0, Tue 11/04/
|
16
|
+
## <a name="v1.1.0"></a>v1.1.0, Tue 11/04/2013
|
36
17
|
|
37
18
|
* Correct/improve autoload behavior
|
38
19
|
* Instead of returning the source **directory** path from
|
39
|
-
[
|
20
|
+
[_Module#autoload?_][Ruby-Core-Module-autoload], return one or more matching
|
40
21
|
source **file** path(s)
|
41
22
|
* Use Ruby load path (`$:`) to handle relative source file paths
|
42
|
-
* Explain
|
43
|
-
[
|
23
|
+
* Explain _Module#autoload?_ and
|
24
|
+
[_Module#constants_][Ruby-Core-Module-constants] in the [readme][readme] and
|
44
25
|
in [inline documentation][inline-documentation]
|
45
26
|
|
46
|
-
## <a name="v1.0.0"></a>v1.0.0, Wed 10/29/
|
27
|
+
## <a name="v1.0.0"></a>v1.0.0, Wed 10/29/2013
|
47
28
|
|
48
29
|
* Add support for Ruby v2.0
|
49
30
|
|
@@ -51,13 +32,8 @@
|
|
51
32
|
|
52
33
|
(First release)
|
53
34
|
|
54
|
-
[
|
55
|
-
[
|
56
|
-
[
|
57
|
-
[
|
58
|
-
[
|
59
|
-
[Ruby-Core-Module-autoload]: https://ruby-doc.org/core/Module.html#method-i-autoload-3F "‘Module#autoload’ method in the Ruby Core Library"
|
60
|
-
[Ruby-Core-Module-constants]: https://ruby-doc.org/core/Module.html#method-i-constants "‘Module#constants’ method in the Ruby Core Library"
|
61
|
-
[Ruby-Stdlib-Pathname]: https://ruby-doc.org/stdlib/libdoc/pathname/rdoc/Pathname.html "‘Pathname’ class in the Ruby Standard Library"
|
62
|
-
[readme]: https://github.com/njonsson/autoloaded/blob/master/README.md "Autoloaded readme"
|
63
|
-
[inline-documentation]: https://www.rubydoc.info/github/njonsson/autoloaded "Autoloaded inline documentation"
|
35
|
+
[JRuby]: http://jruby.org
|
36
|
+
[Ruby-Core-Module-autoload]: http://ruby-doc.org/core/Module.html#method-i-autoload-3F "‘Module#autoload’ method in the Ruby Core Library"
|
37
|
+
[Ruby-Core-Module-constants]: http://ruby-doc.org/core/Module.html#method-i-constants "‘Module#constants’ method in the Ruby Core Library"
|
38
|
+
[readme]: http://github.com/njonsson/autoloaded/blob/master/README.md "Autoloaded readme"
|
39
|
+
[inline-documentation]: http://www.rubydoc.info/github/njonsson/autoloaded "Autoloaded inline documentation"
|
data/License.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# The MIT License
|
2
2
|
|
3
|
-
Source code for
|
3
|
+
Source code for _Autoloaded_ is Copyright © 2014 [Nils Jonsson][mail] and
|
4
4
|
[contributors][contributors].
|
5
5
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
data/README.md
CHANGED
@@ -6,17 +6,18 @@
|
|
6
6
|
[![Code Climate quality report] ][Code-Climate-report]
|
7
7
|
[![Code Climate coverage report]][Code-Climate-report]
|
8
8
|
|
9
|
+
[![Gemnasium build status] ][Gemnasium-build-status]
|
9
10
|
[![Inch CI build status] ][Inch-CI-build-status]
|
10
11
|
[![RubyGems release] ][RubyGems-release]
|
11
12
|
|
12
|
-
If you like the [
|
13
|
-
Ruby Core library, you may have wished for
|
13
|
+
If you like the [_Module#autoload_][Ruby-Core-Module-autoload] feature of the
|
14
|
+
Ruby Core library, you may have wished for _Autoloaded_. It eliminates the
|
14
15
|
drudgery of handcrafting an `autoload` statement for each Ruby source code file
|
15
16
|
in your project. It also avoids the limitations of rigid convention-driven
|
16
17
|
facilities such as those provided by the [ActiveSupport][ActiveSupport-Autoload]
|
17
18
|
RubyGem.
|
18
19
|
|
19
|
-
|
20
|
+
_Autoloaded_ assumes, but does not enforce, `CamelCase`-to-`snake_case`
|
20
21
|
correspondence between the names of constants and source files. You can combine
|
21
22
|
conventions, even putting multiple autoloaded constants in a single source file.
|
22
23
|
|
@@ -26,7 +27,7 @@ Install [the RubyGem][RubyGems-release].
|
|
26
27
|
|
27
28
|
$ gem install autoloaded
|
28
29
|
|
29
|
-
Use
|
30
|
+
Use _Autoloaded_ in your RubyGem project by making it a runtime dependency.
|
30
31
|
|
31
32
|
```ruby
|
32
33
|
# my_awesome_gem.gemspec
|
@@ -38,13 +39,13 @@ Gem::Specification.new do |spec|
|
|
38
39
|
end
|
39
40
|
```
|
40
41
|
|
41
|
-
Or you may want to make
|
42
|
+
Or you may want to make _Autoloaded_ a dependency of your project by using
|
42
43
|
[Bundler][Bundler].
|
43
44
|
|
44
45
|
```ruby
|
45
46
|
# Gemfile
|
46
47
|
|
47
|
-
source '
|
48
|
+
source 'http://rubygems.org'
|
48
49
|
|
49
50
|
gem 'autoloaded', '~> 1'
|
50
51
|
```
|
@@ -65,15 +66,15 @@ Suppose you have the following source files.
|
|
65
66
|
│ └─ version.rb
|
66
67
|
└─ my_awesome_gem.rb
|
67
68
|
|
68
|
-
### The
|
69
|
+
### The _Autoloaded.module_ or _Autoloaded.class_ method
|
69
70
|
|
70
|
-
The
|
71
|
-
[
|
71
|
+
The _Autoloaded.module_ and _Autoloaded.class_ method calls below invoke
|
72
|
+
[_Module#autoload_][Ruby-Core-Module-autoload] for each source file in the
|
72
73
|
calling module’s corresponding directory. Note that these methods must receive a
|
73
74
|
block, even if it’s an empty block.
|
74
75
|
|
75
76
|
The file paths used are abbreviated, if possible, using a directory of the Ruby
|
76
|
-
load path (`$:`). They are also rendered without their
|
77
|
+
load path (`$:`). They are also rendered without their _.rb_ extension.
|
77
78
|
|
78
79
|
```ruby
|
79
80
|
# lib/my_awesome_gem.rb
|
@@ -151,7 +152,7 @@ MyAwesomeGem::DB::Mysql # Raises NameError because
|
|
151
152
|
|
152
153
|
### The `with` specification
|
153
154
|
|
154
|
-
|
155
|
+
_Autoloaded_ needs hints from you concerning unpredictable spellings,
|
155
156
|
stylization, and organization of constant names and/or source file names. You can
|
156
157
|
specify `with` as:
|
157
158
|
|
@@ -172,21 +173,21 @@ You can specify `with` multiple times, and its effects are cumulative.
|
|
172
173
|
# lib/my_awesome_gem.rb
|
173
174
|
module MyAwesomeGem
|
174
175
|
|
175
|
-
Autoloaded.module do |
|
176
|
-
|
176
|
+
Autoloaded.module do |autoloaded|
|
177
|
+
autoloaded.with :DB, :VERSION
|
177
178
|
# Or:
|
178
|
-
#
|
179
|
-
#
|
179
|
+
# autoloaded.with :DB
|
180
|
+
# autoloaded.with :VERSION
|
180
181
|
# Or:
|
181
|
-
#
|
182
|
+
# autoloaded.with DB: 'db', VERSION: 'version'
|
182
183
|
# Or:
|
183
|
-
#
|
184
|
-
#
|
184
|
+
# autoloaded.with DB: 'db'
|
185
|
+
# autoloaded.with VERSION: 'version'
|
185
186
|
# Or:
|
186
|
-
#
|
187
|
+
# autoloaded.with 'db' => :DB, 'version' => :VERSION
|
187
188
|
# Or:
|
188
|
-
#
|
189
|
-
#
|
189
|
+
# autoloaded.with 'db' => :DB
|
190
|
+
# autoloaded.with 'version' => :VERSION
|
190
191
|
end
|
191
192
|
|
192
193
|
# The above is the equivalent of:
|
@@ -201,20 +202,20 @@ module MyAwesomeGem
|
|
201
202
|
|
202
203
|
class DB
|
203
204
|
|
204
|
-
Autoloaded.class do |
|
205
|
-
|
205
|
+
Autoloaded.class do |autoloaded|
|
206
|
+
autoloaded.with :MySQL, :PostgreSQL, [:Access, :SQLServer] => 'MicroSoft'
|
206
207
|
# Or:
|
207
|
-
#
|
208
|
-
#
|
209
|
-
#
|
210
|
-
#
|
208
|
+
# autoloaded.with :MySQL,
|
209
|
+
# :PostgreSQL,
|
210
|
+
# Access: 'MicroSoft',
|
211
|
+
# SQLServer: 'MicroSoft'
|
211
212
|
# Or:
|
212
|
-
#
|
213
|
+
# autoloaded.with :MySQL, :PostgreSQL, 'MicroSoft' => [:Access, :SQLServer]
|
213
214
|
# Or:
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
#
|
215
|
+
# autoloaded.with :MySQL,
|
216
|
+
# :PostgreSQL,
|
217
|
+
# 'MicroSoft' => :Access,
|
218
|
+
# 'MicroSoft' => :SQLServer
|
218
219
|
# Or ...
|
219
220
|
end
|
220
221
|
|
@@ -282,12 +283,12 @@ module MyAwesomeGem
|
|
282
283
|
|
283
284
|
class DB
|
284
285
|
|
285
|
-
Autoloaded.class do |
|
286
|
-
|
286
|
+
Autoloaded.class do |autoloaded|
|
287
|
+
autoloaded.with :MySQL, :PostgreSQL, [:Access, :SQLServer] => 'MicroSoft'
|
287
288
|
|
288
|
-
|
289
|
+
autoloaded.except 'SELF-DESTRUCT!'
|
289
290
|
# Or:
|
290
|
-
#
|
291
|
+
# autoloaded.except :SELF_DESTRUCT_
|
291
292
|
# Or ...
|
292
293
|
end
|
293
294
|
|
@@ -339,9 +340,9 @@ cumulative.
|
|
339
340
|
|
340
341
|
### The `from` specification
|
341
342
|
|
342
|
-
It’s recommended that you call
|
343
|
+
It’s recommended that you call _Autoloaded.module_ or _Autoloaded.class_ from
|
343
344
|
within the source file where your module or class is defined. This practice
|
344
|
-
allows
|
345
|
+
allows _Autoloaded_ to assume that the source files to be autoloaded are in a
|
345
346
|
directory of the same name (and in the same location) as the module’s defining
|
346
347
|
source file.
|
347
348
|
|
@@ -356,12 +357,12 @@ which source files should be autoloaded.
|
|
356
357
|
|
357
358
|
module MyAwesomeGem
|
358
359
|
|
359
|
-
Autoloaded.module do |
|
360
|
+
Autoloaded.module do |autoloaded|
|
360
361
|
# The following code is not actually very useful since the installed location
|
361
362
|
# of a RubyGem varies with the operating system and user preferences. How to
|
362
363
|
# compute the path properly is outside the scope of this readme and is left
|
363
364
|
# as an exercise for the reader.
|
364
|
-
|
365
|
+
autoloaded.from '/absolute/path/to/my_awesome_gem'
|
365
366
|
end
|
366
367
|
|
367
368
|
end
|
@@ -370,18 +371,18 @@ end
|
|
370
371
|
A path provided to `from` cannot be relative; it must start with the filesystem
|
371
372
|
root.
|
372
373
|
|
373
|
-
If you specify `from` multiple times in an
|
374
|
+
If you specify `from` multiple times in an _Autoloaded_ block, only the last one
|
374
375
|
takes effect.
|
375
376
|
|
376
|
-
### The
|
377
|
+
### The _Autoloaded.warn_ method
|
377
378
|
|
378
|
-
There are two circumstances under which
|
379
|
+
There are two circumstances under which _Autoloaded_ by default will write
|
379
380
|
warnings to stderr:
|
380
381
|
|
381
382
|
* Overriding an established autoload
|
382
383
|
* Establishing an autoload for a defined constant
|
383
384
|
|
384
|
-
You can silence these warnings by passing `false` to
|
385
|
+
You can silence these warnings by passing `false` to _Autoloaded.warn_. (Passing
|
385
386
|
`true` turns warnings on if they are off.)
|
386
387
|
|
387
388
|
```ruby
|
@@ -437,7 +438,7 @@ end
|
|
437
438
|
|
438
439
|
### How to debug autoloading
|
439
440
|
|
440
|
-
The
|
441
|
+
The _Autoloaded.module_ or _Autoloaded.class_ method returns an ordered list of
|
441
442
|
arguments it has passed to `autoload`.
|
442
443
|
|
443
444
|
```ruby
|
@@ -447,9 +448,9 @@ module MyAwesomeGem
|
|
447
448
|
|
448
449
|
class DB
|
449
450
|
|
450
|
-
results = Autoloaded.class do |
|
451
|
-
|
452
|
-
|
451
|
+
results = Autoloaded.class do |autoloaded|
|
452
|
+
autoloaded.with :MySQL, :PostgreSQL, [:Access, :SQLServer] => 'MicroSoft'
|
453
|
+
autoloaded.except 'SELF-DESTRUCT!'
|
453
454
|
end
|
454
455
|
STDOUT.puts results.inspect # See output below.
|
455
456
|
|
@@ -464,20 +465,20 @@ end
|
|
464
465
|
# [:PostgreSQL, 'my_awesome_gem/db/postgre_sql']]
|
465
466
|
```
|
466
467
|
|
467
|
-
You can also hook [
|
468
|
-
[
|
468
|
+
You can also hook [_Module#autoload_][Ruby-Core-Module-autoload] and
|
469
|
+
[_Kernel#autoload_][Ruby-Core-Kernel-autoload] via monkeypatching or other means
|
469
470
|
in order to see what’s happening.
|
470
471
|
|
471
472
|
### Source filenames are relative to the `from` specification
|
472
473
|
|
473
474
|
You may have noticed that source filenames in the above examples are not
|
474
|
-
absolute. They are relative to the
|
475
|
+
absolute. They are relative to the _Autoloaded_ block’s `from` specification
|
475
476
|
(which I recommend that you allow to be computed for you —
|
476
477
|
[see above](#the-from-specification)).
|
477
478
|
|
478
479
|
### Recursive autoloading not supported
|
479
480
|
|
480
|
-
|
481
|
+
_Autoloaded_ does not perform deep autoloading of nested namespaces and
|
481
482
|
directories. This is by design.
|
482
483
|
|
483
484
|
## Contributing
|
@@ -488,39 +489,28 @@ directories. This is by design.
|
|
488
489
|
4. Push to the branch: `git push origin my-new-feature`.
|
489
490
|
5. [Create][compare-Autoloaded-branches] a new pull request.
|
490
491
|
|
491
|
-
Development
|
492
|
-
-----------
|
493
|
-
|
494
|
-
After cloning the repository, `bin/setup` to install dependencies. Then `rake` to
|
495
|
-
run the tests. You can also `bin/console` to get an interactive prompt that will
|
496
|
-
allow you to experiment.
|
497
|
-
|
498
|
-
To install this gem onto your local machine, `bundle exec rake install`. To
|
499
|
-
release a new version, update the version number in *lib/autoloaded/version.rb*,
|
500
|
-
and then `bundle exec rake release`, which will create a Git tag for the version,
|
501
|
-
push Git commits and tags, and push the *.gem* file to
|
502
|
-
[RubyGems.org](RubyGems-release).
|
503
|
-
|
504
492
|
## License
|
505
493
|
|
506
494
|
Released under the [MIT License][MIT-License].
|
507
495
|
|
508
496
|
[Autoloaded graphic]: https://farm5.staticflickr.com/4134/4941065976_54737fe145.jpg
|
509
|
-
[Travis CI build status]: https://secure.travis-ci.org/njonsson/autoloaded.svg?branch=
|
497
|
+
[Travis CI build status]: https://secure.travis-ci.org/njonsson/autoloaded.svg?branch=master
|
510
498
|
[Code Climate quality report]: https://codeclimate.com/github/njonsson/autoloaded/badges/gpa.svg
|
511
499
|
[Code Climate coverage report]: https://codeclimate.com/github/njonsson/autoloaded/badges/coverage.svg
|
512
|
-
[
|
500
|
+
[Gemnasium build status]: https://gemnasium.com/njonsson/autoloaded.svg
|
501
|
+
[Inch CI build status]: http://inch-ci.org/github/njonsson/autoloaded.svg?branch=master
|
513
502
|
[RubyGems release]: https://badge.fury.io/rb/autoloaded.svg
|
514
503
|
|
515
|
-
[spider-gear-image]: https://www.flickr.com/photos/dongkwan/4941065976
|
516
|
-
[Travis-CI-build-status]:
|
517
|
-
[Code-Climate-report]:
|
518
|
-
[
|
519
|
-
[
|
520
|
-
[
|
521
|
-
[
|
522
|
-
[
|
523
|
-
[
|
524
|
-
[
|
525
|
-
[
|
526
|
-
[
|
504
|
+
[spider-gear-image]: https://www.flickr.com/photos/dongkwan/4941065976 "spider gear image by Ernesto Andrade"
|
505
|
+
[Travis-CI-build-status]: http://travis-ci.org/njonsson/autoloaded "Travis CI build status for Autoloaded"
|
506
|
+
[Code-Climate-report]: http://codeclimate.com/github/njonsson/autoloaded "Code Climate report for Autoloaded"
|
507
|
+
[Gemnasium-build-status]: http://gemnasium.com/njonsson/autoloaded "Gemnasium build status for Autoloaded"
|
508
|
+
[Inch-CI-build-status]: http://inch-ci.org/github/njonsson/autoloaded "Inch CI build status for Autoloaded"
|
509
|
+
[RubyGems-release]: http://rubygems.org/gems/autoloaded "RubyGems release of Autoloaded"
|
510
|
+
[Ruby-Core-Module-autoload]: http://ruby-doc.org/core/Module.html#method-i-autoload "‘Module#autoload’ method in the Ruby Core Library"
|
511
|
+
[ActiveSupport-Autoload]: http://api.rubyonrails.org/classes/ActiveSupport/Autoload.html "‘ActiveSupport::Autoload’ module in the Rails API"
|
512
|
+
[Bundler]: http://bundler.io
|
513
|
+
[Ruby-Core-Kernel-autoload]: http://ruby-doc.org/core/Kernel.html#method-i-autoload "‘Kernel#autoload’ method in the Ruby Core Library"
|
514
|
+
[fork-Autoloaded]: https://github.com/njonsson/autoloaded/fork "Fork the official repository of Autoloaded"
|
515
|
+
[compare-Autoloaded-branches]: https://github.com/njonsson/autoloaded/compare "Compare branches of Autoloaded repositories"
|
516
|
+
[MIT-License]: http://github.com/njonsson/autoloaded/blob/master/License.md "MIT License claim for Autoloaded"
|