require_dir 1.0.0 → 2.0.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.
- checksums.yaml +5 -5
- data/.travis.yml +14 -13
- data/README.md +29 -24
- data/lib/require_dir.rb +8 -6
- data/lib/require_dir/initializer.rb +20 -23
- data/lib/require_dir/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2faa13586135684abb096c092fef2daaa002796a
|
4
|
+
data.tar.gz: 1c0d386ce4b9c18e771b78ee0b85d3f64e4c7c72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f24094cb68704a8c7fe3ef97bf8d281515399c9401ab56aff1e59820ba3d84c862a0eb4aa89fd655760f8f645b6e160faa7b612356db4850a624495e504eea3
|
7
|
+
data.tar.gz: 020ad935bf36cfc904179f7774780f0958d43752af0b0a07b5978e1f52eb94fbe0877b0812628d4c8df193fce4307428f0704ec06dfc79706d5fd0edae0c07f1
|
data/.travis.yml
CHANGED
@@ -1,23 +1,24 @@
|
|
1
1
|
language: ruby
|
2
|
-
env:
|
3
|
-
global:
|
4
|
-
- CODECLIMATE_REPO_TOKEN=703cb4759e977bdd9502305ae454a0acdf7bd0d51d418e88048110f4735c4a80
|
5
2
|
rvm:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
- 2.2.9
|
4
|
+
- 2.3.6
|
5
|
+
- 2.4.3
|
6
|
+
- 2.5.0
|
10
7
|
before_script:
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
|
9
|
+
> ./cc-test-reporter
|
10
|
+
- chmod +x ./cc-test-reporter
|
11
|
+
- "./cc-test-reporter before-build"
|
14
12
|
script:
|
15
|
-
|
13
|
+
- bundle exec rspec
|
16
14
|
after_script:
|
17
|
-
|
15
|
+
- "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
18
16
|
notifications:
|
19
17
|
email:
|
20
18
|
recipients:
|
21
|
-
|
19
|
+
- kigster@gmail.com
|
22
20
|
on_success: change
|
23
21
|
on_failure: always
|
22
|
+
env:
|
23
|
+
global:
|
24
|
+
secure: KFl7jV0zv/OZ/Hi+IBI8fDaMEfWjbYOZBAmlPZp3N5A1YcHT/7oqGguUgrYWKfBM84CMZOzszKw7yVvzdn6pvate+0nP22hfwCwT6hRly56c/oMLJvm/Sud+hSsL7Aq7lZq3UeuDDUzPcoyCA6h3hqve4RX93w/A5a4yQYE6N8PJbyZwFZ+uf3MvnoyIRTFAW5Rjrk23ieSjBsG8zdIUabYahAGUkm0tZt7SXmEyFi5ghMpY8WFeUl3cwnlhVjYyZ+/qfTdzW1vFhJ11ZObrQPCaMb1te/Wh0/WoUE/ycbUPkxPWEfd7KDThb6x9QVzK28ssIgB1w7VmHpAa9h77vu9UaZvJTcS8Ud/gQaTE00VinEeK/wOA2CgLIcUnK4bjbCeZ+bgMjjKhN1JPJZvx+xsk19IHTT3DuQF+olkPJV3NU4o0ZjRBwbi4tNGuboJiDC+op/WiKDGsdTzSqA3TWNIQZzfVI+x64YcHZ5OjZHC1kNdeKd51kjITRbtp3RAepCeITQMZKLiS66k7tLtqkf8zMdkIUHFCBon5TXlclnVzCwqxtySk4RDOQ0ac0zgot/MnXXhEJkkgd9Qo+51Yd0DBCzkZgJfRWNKCv/MmAyn7K2kq3COfNDoS/C9JEQzFapj3CNdntdCZWHUTwiug0y/DBxSzyRagbwyoVObVBfY=
|
data/README.md
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
[](https://travis-ci.org/kigster/require_dir)
|
2
|
+
[](https://codeclimate.com/github/kigster/require_dir/maintainability)
|
3
|
+
[](https://codeclimate.com/github/kigster/require_dir/test_coverage)
|
3
4
|
[](https://badge.fury.io/rb/require_dir)
|
4
5
|
[](https://rubygems.org/gems/require_dir)
|
5
6
|
|
6
|
-
|
7
|
-
[](https://codeclimate.com/github/kigster/require_dir/test_coverage)
|
8
|
-
[](https://codeclimate.com/github/kigster/require_dir/maintainability)
|
9
|
-
[](https://codeclimate.com/github/kigster/require_dir)
|
7
|
+
----
|
10
8
|
|
9
|
+
# RequireDir
|
11
10
|
|
12
11
|
This gem provides an easy way to require all file from a folder – recursively, or not.
|
13
12
|
|
@@ -41,37 +40,41 @@ Recommended usage is to include this gem's module into the top level module of y
|
|
41
40
|
# file 'lib/mylib.rb' -- top level file for a gem 'mylib'
|
42
41
|
require 'require_dir'
|
43
42
|
module Mylib
|
43
|
+
# You must pass __FILE__ so that the library knows the "root" of your sources.
|
44
44
|
RequireDir.enable_require_dir!(self, __FILE__)
|
45
|
-
end
|
46
|
-
|
47
|
-
Mylib.require_dir('mylib/subfolder') # loads all files in the folder 'lib/mylib/subfolder/*.rb'
|
48
|
-
Mylib.require_dir_r('mylib/subfolder') # recursive load from 'lib/mylib/subfolder/**/*.rb'
|
49
45
|
|
46
|
+
dir_r 'mylib/cli'
|
47
|
+
dir 'mylib/commands'
|
48
|
+
end
|
50
49
|
```
|
51
50
|
|
52
|
-
You
|
51
|
+
You literally have access to two methods (with aliases):
|
53
52
|
|
53
|
+
* `dir_r` (or `require_dir_r`) loads all ruby files recursively
|
54
|
+
* `dir` (or `require_dir`) loads files non-recursively
|
54
55
|
|
55
|
-
### Offset
|
56
|
-
|
57
|
-
You can optionally load the library using `init_with_offset` method, which allows you
|
58
|
-
to initialize the library from a file located not directly under lib, but further down below.
|
59
56
|
|
60
|
-
|
61
|
-
be able to later use RequireDir to load files relative to `lib`. This is how you would do that:
|
57
|
+
### Offset
|
62
58
|
|
59
|
+
If your library's top required file is not at the very top level of the directory structure,
|
60
|
+
which might happen, if, say you have a gem named `app-foo`, and your primary required file is
|
61
|
+
located in `lib/app/foo.rb`, in this case you will need to pass an offset of 1 to the `enable_require_dir!`
|
62
|
+
method to properly initialize recursive loading:
|
63
63
|
|
64
64
|
```ruby
|
65
|
-
#
|
65
|
+
# 'lib/app/foo.rb'
|
66
|
+
# i.e. this file is one level deep in the source tree of this library:
|
67
|
+
|
66
68
|
require 'require_dir'
|
67
|
-
|
68
|
-
|
69
|
-
|
69
|
+
|
70
|
+
module App
|
71
|
+
module Foo
|
72
|
+
# offset is 1, because the current file is 1 level deep into the source tree.
|
73
|
+
RequireDir.enable_require_dir!(self, __FILE__, 1)
|
74
|
+
|
75
|
+
dir_r 'app/foo/bar' # loads all files in the folder 'app/foo/bar/**.rb'
|
70
76
|
end
|
71
77
|
end
|
72
|
-
|
73
|
-
Mylib.dir('mylib/subfolder') # loads all files in the folder 'lib/mylib/subfolder/*.rb'
|
74
|
-
Mylib.dir_r('mylib/subfolder') # recursive load from 'lib/mylib/subfolder/**/*.rb'
|
75
78
|
```
|
76
79
|
|
77
80
|
### Load Errors
|
@@ -85,7 +88,9 @@ exploded. You can enable debugging output using two methods:
|
|
85
88
|
* Initialize library with options hash, setting:
|
86
89
|
|
87
90
|
```ruby
|
91
|
+
module Foo
|
88
92
|
RequireDir.enable_require_dir!(self, __FILE__, 0, debug: true)
|
93
|
+
end
|
89
94
|
```
|
90
95
|
|
91
96
|
## Development
|
data/lib/require_dir.rb
CHANGED
@@ -16,19 +16,21 @@ require 'require_dir/initializer'
|
|
16
16
|
# RequireDir.enable(self, __FILE__)
|
17
17
|
# end
|
18
18
|
# end
|
19
|
-
# Foo::Bar.
|
19
|
+
# Foo::Bar.dir_r 'foo/bar/commands' # loads all 'foo/bar/commands/**.rb' files
|
20
|
+
# Foo::Bar.dir_r 'foo/bar/commands' # loads all 'foo/bar/commands/*.rb' files
|
21
|
+
#
|
20
22
|
module RequireDir
|
21
23
|
class << self
|
22
24
|
# @deprecated Please use {#enable_require_dir!} instead
|
23
25
|
def included(klass)
|
24
|
-
klass.extend
|
25
|
-
klass.include
|
26
|
+
klass.send(:extend, RequireDir::Initializer)
|
27
|
+
klass.send(:include, RequireDir::Initializer)
|
26
28
|
end
|
27
29
|
|
28
30
|
def enable_require_dir!(klass, source_file, offset = 0, **options)
|
29
|
-
klass.extend
|
30
|
-
klass.include
|
31
|
-
klass.
|
31
|
+
klass.send(:extend, RequireDir::Initializer)
|
32
|
+
klass.send(:include, RequireDir::Initializer)
|
33
|
+
klass.send(:__require_dir_init, source_file, offset, options)
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -1,32 +1,29 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
module RequireDir
|
3
3
|
module Initializer
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
extend Forwardable
|
11
|
-
def_delegators :@loader, :dir, :dir_r, :require_dir, :require_dir_r
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
4
|
+
def self.included(base)
|
5
|
+
base.instance_eval do
|
6
|
+
class << self
|
7
|
+
attr_accessor :__require_dir_loader
|
8
|
+
extend Forwardable
|
9
|
+
def_delegators :@__require_dir_loader, :dir, :dir_r, :require_dir, :require_dir_r
|
16
10
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
def __require_dir_init(source, offset = 0, options = {})
|
12
|
+
project_folder = __require_dir_project_folder(source: source, offset: offset)
|
13
|
+
self.__require_dir_loader = __require_dir_create_loader(options, project_folder)
|
14
|
+
end
|
21
15
|
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
def __require_dir_create_loader(options, project_folder)
|
17
|
+
RequireDir::Loader.new(project_folder, options)
|
18
|
+
end
|
25
19
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
20
|
+
def __require_dir_project_folder(source:, offset: 0)
|
21
|
+
dirs_up = ''
|
22
|
+
offset.times { dirs_up << '/..' } if offset > 0
|
23
|
+
File.dirname(File.expand_path(source + dirs_up))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
30
27
|
end
|
31
28
|
end
|
32
29
|
end
|
data/lib/require_dir/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: require_dir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Gredeskoul
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colored2
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.4.5.2
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: Easily and non-intrusively require files from sub-folders
|