require_dir 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/require_dir.rb +22 -0
- data/lib/require_dir/loader.rb +31 -0
- data/lib/require_dir/version.rb +3 -0
- data/require_dir.gemspec +23 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f3736948105874efc590daf353501eb58aca7168
|
4
|
+
data.tar.gz: 0357f6c0ded53f5d5e9760c422b2ad1567282042
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c9d531f6059b880bde11664c373d0355ed79210165f28eceb64a1350b62a9cb2ce82ad2c3bced1966e3dc3c2f67f3cb74436b59a26a0d154b2585df5a33fcca
|
7
|
+
data.tar.gz: f482e57c9846b2e334c69519529a5ce2cabad33ba18ace4b491f70b13ee00d7f62c2100e1ddfca0c71f51bded573d09b11f1c2ef67377f5555f5d59d390fcb30
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Konstantin Gredeskoul
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# RequireDir
|
2
|
+
|
3
|
+
This gem provides an easy way to require all file from a folder – recursively, or not.
|
4
|
+
|
5
|
+
Unlike other gems, such as `require_all`, this gem does suffer from module clobbering or changing global search paths.
|
6
|
+
|
7
|
+
## Author
|
8
|
+
|
9
|
+
This library is the work of [Konstantin Gredeskoul](http:/kig.re), © 2016.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'require_dir'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it with `gem` command:
|
24
|
+
|
25
|
+
$ gem install require_dir
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Recommended usage is to include this gem's module into the top level module of your library, like so:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
# file 'lib/mylib.rb' -- top level file for a gem 'mylib'
|
33
|
+
require 'require_dir'
|
34
|
+
module Mylib
|
35
|
+
extend RequireDir
|
36
|
+
init_from_source __FILE__
|
37
|
+
end
|
38
|
+
|
39
|
+
Mylib.dir('mylib/subfolder') # loads all files in the folder 'lib/mylib/subfolder/*.rb'
|
40
|
+
Mylib.dir_r('mylib/subfolder') # recursive load from 'lib/mylib/subfolder/**/*.rb'
|
41
|
+
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/require_dir.
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
58
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "require_dir"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/require_dir.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'require_dir/version'
|
2
|
+
require 'require_dir/loader'
|
3
|
+
require 'forwardable'
|
4
|
+
module RequireDir
|
5
|
+
attr_accessor :loader
|
6
|
+
|
7
|
+
def project_folder_from(source: , offset: 0)
|
8
|
+
dirs_up = ''
|
9
|
+
offset.times { dirs_up << '/..' } if offset > 0
|
10
|
+
File.dirname(File.expand_path(source + dirs_up))
|
11
|
+
end
|
12
|
+
|
13
|
+
def init_from_source(source, offset = 0, options = {})
|
14
|
+
project_folder = project_folder_from(source: source, offset: offset)
|
15
|
+
self.loader = RequireDir::Loader.new(project_folder, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
extend Forwardable
|
19
|
+
def_delegators :@loader, :dir, :dir_r
|
20
|
+
|
21
|
+
extend self
|
22
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'require_dir/version'
|
2
|
+
|
3
|
+
module RequireDir
|
4
|
+
#
|
5
|
+
# This class is meant to be instantiated per project/library, and then used to load
|
6
|
+
# en masse ruby files from a directory.
|
7
|
+
class Loader
|
8
|
+
|
9
|
+
attr_accessor :project_root, :options
|
10
|
+
|
11
|
+
def initialize(root_dir, options = {})
|
12
|
+
raise ArgumentError.new("Folder #{root_dir} is not found") unless Dir.exist?(root_dir)
|
13
|
+
self.project_root = root_dir
|
14
|
+
self.options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def dir(folder, recursive = false)
|
18
|
+
folder = "/#{folder}" unless folder.start_with? '/'
|
19
|
+
loader = self
|
20
|
+
::Dir.glob(project_root + folder + (recursive ? '/**/*.rb' : '/*.rb') ) do |file|
|
21
|
+
puts "Loading #{file}" if loader.options[:debug]
|
22
|
+
Kernel.require(file)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def dir_r(folder)
|
27
|
+
dir(folder, true)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/require_dir.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 'require_dir/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'require_dir'
|
8
|
+
spec.version = RequireDir::VERSION
|
9
|
+
spec.authors = ['Konstantin Gredeskoul']
|
10
|
+
spec.email = ['kig@reinvent.one']
|
11
|
+
|
12
|
+
spec.summary = %q{Easily and non-intrusively require files from sub-folders}
|
13
|
+
spec.description = %q{Without polluting global namespace, or having modules clobber each other, include RequireDir and initialize it to get access to #dir and #dir_r}
|
14
|
+
spec.homepage = 'https://github.com/kigster/require_dir'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.require_paths = %w(lib)
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: require_dir
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Konstantin Gredeskoul
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-03 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.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: 'Without polluting global namespace, or having modules clobber each other,
|
56
|
+
include RequireDir and initialize it to get access to #dir and #dir_r'
|
57
|
+
email:
|
58
|
+
- kig@reinvent.one
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/require_dir.rb
|
73
|
+
- lib/require_dir/loader.rb
|
74
|
+
- lib/require_dir/version.rb
|
75
|
+
- require_dir.gemspec
|
76
|
+
homepage: https://github.com/kigster/require_dir
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.5.1
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Easily and non-intrusively require files from sub-folders
|
100
|
+
test_files: []
|