autoloading 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +1 -0
- data/autoloading.gemspec +23 -0
- data/lib/autoloading.rb +22 -0
- data/lib/autoloading/version.rb +3 -0
- data/test/autoloading_spec.rb +32 -0
- data/test/support/test_files.rb +17 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 88047665a7fc66a53c7829886ac80d920f16508c
|
4
|
+
data.tar.gz: b43cf90d9376c24bc6db227b4957ee68a96358df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 90b7dc3efac44574637277def4d3f616fe4b6698adb82c3591c3c4fd280d87009a96acc70465593adfb84b5c7ea263475d2cd5a9a37aaedf9a35767b74499a71
|
7
|
+
data.tar.gz: c9c2a6d93064fd0f2881e8d17cc80f91b18aa573939ef35dd0fd74d5899eebe578ff239d43c645d5b5dd6462b279aad619e2807e740a82edc00eec670d9c2ccb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Levente Bagi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Autoloading
|
2
|
+
|
3
|
+
Autoload Ruby classes or modules by inferring the file path from the name
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'autoloading'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install autoloading
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
# hello.rb
|
22
|
+
module Hello
|
23
|
+
extend Autoloading
|
24
|
+
end
|
25
|
+
|
26
|
+
# hello/kitty.rb
|
27
|
+
module Hello::Kitty
|
28
|
+
end
|
29
|
+
|
30
|
+
require 'hello'
|
31
|
+
Hello::Kitty
|
32
|
+
|
33
|
+
## See also
|
34
|
+
|
35
|
+
* [application_module gem](https://github.com/bagilevi/application_module)
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it ( http://github.com/bagilevi/autoloading/fork )
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/autoloading.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'autoloading/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "autoloading"
|
8
|
+
spec.version = Autoloading::VERSION
|
9
|
+
spec.authors = ["Levente Bagi"]
|
10
|
+
spec.email = ["bagilevi@gmail.com"]
|
11
|
+
spec.summary = %q{Autoload Ruby classes or modules}
|
12
|
+
spec.description = %q{Autoload Ruby classes or modules by inferring the file path from the name}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/autoloading.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "autoloading/version"
|
2
|
+
|
3
|
+
module Autoloading
|
4
|
+
def const_missing(cname)
|
5
|
+
prefix = underscore(self.name.to_s)
|
6
|
+
filename = underscore(cname.to_s)
|
7
|
+
path = "#{prefix}/#{filename}"
|
8
|
+
require path
|
9
|
+
const_get(cname)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Based on ActiveSupport, removed inflections.
|
13
|
+
# https://github.com/rails/rails/blob/v4.1.0.rc1/activesupport/lib/active_support/inflector/methods.rb
|
14
|
+
def underscore(camel_cased_word)
|
15
|
+
word = camel_cased_word.to_s.gsub('::', '/')
|
16
|
+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
|
17
|
+
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
18
|
+
word.tr!("-", "_")
|
19
|
+
word.downcase!
|
20
|
+
word
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
$: << Pathname.new(File.dirname(__FILE__)).join('..', 'lib')
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'autoloading'
|
5
|
+
require_relative 'support/test_files'
|
6
|
+
|
7
|
+
|
8
|
+
describe Autoloading do
|
9
|
+
include TestFiles
|
10
|
+
|
11
|
+
after do
|
12
|
+
delete_test_files
|
13
|
+
end
|
14
|
+
|
15
|
+
it "works" do
|
16
|
+
create_test_file "hello.rb", <<-FILE
|
17
|
+
module Hello
|
18
|
+
extend Autoloading
|
19
|
+
end
|
20
|
+
FILE
|
21
|
+
|
22
|
+
create_test_file "hello/kitty.rb", <<-FILE
|
23
|
+
module Hello::Kitty
|
24
|
+
end
|
25
|
+
FILE
|
26
|
+
|
27
|
+
$: << test_file_root.to_s
|
28
|
+
require 'hello'
|
29
|
+
Hello::Kitty
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
module TestFiles
|
3
|
+
def test_file_root
|
4
|
+
Pathname.new(File.dirname(__FILE__)).join('..', '..', 'tmp', 'file_tests')
|
5
|
+
end
|
6
|
+
|
7
|
+
def create_test_file(name, contents)
|
8
|
+
path = test_file_root.join(name)
|
9
|
+
FileUtils.mkdir_p(File.dirname(path))
|
10
|
+
File.open(path, 'w') { |f| f.write(contents) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete_test_files
|
14
|
+
FileUtils.rm_rf(test_file_root.to_s)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: autoloading
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Levente Bagi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Autoload Ruby classes or modules by inferring the file path from the
|
42
|
+
name
|
43
|
+
email:
|
44
|
+
- bagilevi@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- autoloading.gemspec
|
55
|
+
- lib/autoloading.rb
|
56
|
+
- lib/autoloading/version.rb
|
57
|
+
- test/autoloading_spec.rb
|
58
|
+
- test/support/test_files.rb
|
59
|
+
homepage: ''
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.2.1
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Autoload Ruby classes or modules
|
83
|
+
test_files:
|
84
|
+
- test/autoloading_spec.rb
|
85
|
+
- test/support/test_files.rb
|