zeroload 0.0.1
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.
- checksums.yaml +7 -0
- data/README.markdown +75 -0
- data/Rakefile +10 -0
- data/lib/zeroload/auto.rb +7 -0
- data/lib/zeroload/version.rb +5 -0
- data/lib/zeroload.rb +21 -0
- data/zeroload.gemspec +33 -0
- metadata +53 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8ff5fae430018bfb1219524cfd85e641487ccdd4
|
4
|
+
data.tar.gz: cf6085c9d9b835345a5046aaf4a4e8822cd9015f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 830b47b027951eafaf5b6175d1f4ab23c94a81b03a10468e9518618ad54ee8f133b0f2cdff2bda0c97334282943c9b543b1a49f4831598eda87e81952d70668a
|
7
|
+
data.tar.gz: f2799be3bdb1aae80d1082fbb061743bb1b9e36faa81b1773f6014d11c7deec7bb931dbac07f9bf4e411ccaa4e97395709224fae0272a59518c1732f2476a972
|
data/README.markdown
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
README
|
2
|
+
======
|
3
|
+
|
4
|
+
|
5
|
+
Summary
|
6
|
+
-------
|
7
|
+
|
8
|
+
Automatically autoload all constants for a module.
|
9
|
+
Reduces your requires to one line per file, plus external dependencies.
|
10
|
+
Enables requiring always only the precise file holding the constant you
|
11
|
+
depend on (or top level if you depend on many).
|
12
|
+
|
13
|
+
|
14
|
+
Installation
|
15
|
+
------------
|
16
|
+
|
17
|
+
`gem install zeroload`
|
18
|
+
|
19
|
+
|
20
|
+
Usage
|
21
|
+
-----
|
22
|
+
|
23
|
+
Map your constants to filenames by replacing :: with /. For example, the
|
24
|
+
constant Foo::BarBaz should be defined in file lib/Foo/BarBaz.rb. Note that
|
25
|
+
the case matters! Each file should require the nesting namespace. That is,
|
26
|
+
Foo/BarBaz.rb should require "Foo". All modules & classes always use
|
27
|
+
zeroload.
|
28
|
+
|
29
|
+
### Example
|
30
|
+
|
31
|
+
Given the files
|
32
|
+
|
33
|
+
* lib/Foo.rb
|
34
|
+
* lib/Foo/Bar.rb
|
35
|
+
|
36
|
+
The contents of lib/Foo.rb is:
|
37
|
+
|
38
|
+
require "zeroload"
|
39
|
+
|
40
|
+
module Foo
|
41
|
+
zeroload!
|
42
|
+
|
43
|
+
# Code of Foo
|
44
|
+
end
|
45
|
+
|
46
|
+
And the contents of lib/Foo/bar.rb is:
|
47
|
+
|
48
|
+
require "Foo"
|
49
|
+
|
50
|
+
module Foo
|
51
|
+
class Bar
|
52
|
+
zeroload! # only necessary if there's stuff nested below
|
53
|
+
|
54
|
+
# Code of Foo::Bar
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
Description
|
60
|
+
-----------
|
61
|
+
|
62
|
+
Automatically autoload all constants for a module. This requires a change from
|
63
|
+
the current convention of putting class Foo::BarBaz into foo/barbaz.rb (or
|
64
|
+
foo/bar_baz.rb in rails) to using Foo/BarBaz.rb instead.
|
65
|
+
|
66
|
+
|
67
|
+
Caveats
|
68
|
+
-------
|
69
|
+
|
70
|
+
* **Q:** But didn't have Kernel#autoload problems with multi-threading?
|
71
|
+
* **A:** Yes, it did. They've since been resolved:
|
72
|
+
* [see bug 921](https://bugs.ruby-lang.org/issues/921)
|
73
|
+
* [see Revision 33078](https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/33078)
|
74
|
+
* **Q:** But isn't Kernel#autoload deprecated?
|
75
|
+
* **A:** Sadly, the state on this is not entirely clear. But it seems it is no longer deprecated.
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path('../rake/lib', __FILE__))
|
2
|
+
Dir.glob(File.expand_path('../rake/tasks/**/*.{rake,task,rb}', __FILE__)) do |task_file|
|
3
|
+
begin
|
4
|
+
import task_file
|
5
|
+
rescue LoadError => e
|
6
|
+
warn "Failed to load task file #{task_file}"
|
7
|
+
warn " #{e.class} #{e.message}"
|
8
|
+
warn " #{e.backtrace.first}"
|
9
|
+
end
|
10
|
+
end
|
data/lib/zeroload.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'zeroload/version'
|
2
|
+
require 'zeroload/auto'
|
3
|
+
|
4
|
+
# Zeroload
|
5
|
+
# Automatically autoload all constants for a module. This requires a change from
|
6
|
+
# the current convention of putting class Foo::BarBaz into foo/barbaz.rb (or
|
7
|
+
# foo/bar_baz.rb in rails) to using Foo/BarBaz.rb instead.
|
8
|
+
module Zeroload
|
9
|
+
def self.module(mod, directory=nil)
|
10
|
+
directory ||= caller_locations.first.absolute_path.sub(/\.[^.]*\z/, "".freeze)
|
11
|
+
|
12
|
+
Dir.glob("#{directory}/*.{rb,so,bundle,dll}") do |path|
|
13
|
+
name = File.basename(path)
|
14
|
+
if /\A[A-Z]/ =~ name
|
15
|
+
name.sub!(/\.[^.]*\z/, "".freeze)
|
16
|
+
warn "#{mod} autoloads #{name} from #{path}" if $VERBOSE
|
17
|
+
mod.autoload :"#{name}", path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/zeroload.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "zeroload"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.authors = "Stefan Rusterholz"
|
5
|
+
s.email = "stefan.rusterholz@gmail.com"
|
6
|
+
s.homepage = "https://github.com/apeiros/jacob"
|
7
|
+
s.license = "BSD 2-Clause"
|
8
|
+
|
9
|
+
s.description = <<-DESCRIPTION.gsub(/^ /, '').chomp
|
10
|
+
Automatically autoload all constants for a module. This requires a change from
|
11
|
+
the current convention of putting class Foo::BarBaz into foo/barbaz.rb (or
|
12
|
+
foo/bar_baz.rb in rails) to using Foo/BarBaz.rb instead.
|
13
|
+
DESCRIPTION
|
14
|
+
s.summary = <<-SUMMARY.gsub(/^ /, '').chomp
|
15
|
+
Automatically autoload all constants for a module.
|
16
|
+
SUMMARY
|
17
|
+
|
18
|
+
s.required_ruby_version = ">= 2.1.0" # TODO: figure out, when autoload became thread-safe
|
19
|
+
s.files =
|
20
|
+
Dir['bin/**/*'] +
|
21
|
+
Dir['lib/**/*'] +
|
22
|
+
Dir['rake/**/*'] +
|
23
|
+
Dir['test/**/*'] +
|
24
|
+
Dir["*.gemspec"] +
|
25
|
+
%w[
|
26
|
+
Rakefile
|
27
|
+
README.markdown
|
28
|
+
]
|
29
|
+
|
30
|
+
if File.directory?('bin') then
|
31
|
+
s.executables = Dir.chdir('bin') { Dir.glob('**/*').select { |f| File.executable?(f) } }
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zeroload
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stefan Rusterholz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |-
|
14
|
+
Automatically autoload all constants for a module. This requires a change from
|
15
|
+
the current convention of putting class Foo::BarBaz into foo/barbaz.rb (or
|
16
|
+
foo/bar_baz.rb in rails) to using Foo/BarBaz.rb instead.
|
17
|
+
email: stefan.rusterholz@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- README.markdown
|
23
|
+
- Rakefile
|
24
|
+
- lib/zeroload.rb
|
25
|
+
- lib/zeroload/auto.rb
|
26
|
+
- lib/zeroload/version.rb
|
27
|
+
- zeroload.gemspec
|
28
|
+
homepage: https://github.com/apeiros/jacob
|
29
|
+
licenses:
|
30
|
+
- BSD 2-Clause
|
31
|
+
metadata: {}
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.1.0
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 2.4.5.1
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: Automatically autoload all constants for a module.
|
52
|
+
test_files: []
|
53
|
+
has_rdoc:
|