requires 0.2.0 → 1.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 +4 -4
- data/README.md +18 -24
- data/lib/requires.rb +14 -17
- metadata +8 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4cb5240d4eb6c1a4650aed842aaef7229cf6e1a2ffe4480563aac7a3c29e2011
|
|
4
|
+
data.tar.gz: 9f9c1818cf1a9edf762e9e912f465fd5c6c1424957ddadb3539f24bc30307ec7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fc5ac89b618747966124f1c04ed79eeb3f4fa8a5563b31a72dd184e413c81ff17dab041c297ae66df7a77a2954872bf51a05d2fdb8f6a807aebf657cf3affbe6
|
|
7
|
+
data.tar.gz: 5d8249cdb56962d0c7fd53d97cd66792e9d1c923cb0b7b0c2732d109b3c46e292bb2e1a3defb412e0c198f0eafbf6b9f116b30f051351e61e4b0e5b13defe53d
|
data/README.md
CHANGED
|
@@ -1,35 +1,29 @@
|
|
|
1
|
-
Requires
|
|
2
|
-
==================================================
|
|
1
|
+
# Requires
|
|
3
2
|
|
|
4
3
|
[](https://badge.fury.io/rb/requires)
|
|
5
|
-
[](https://github.com/DannyBen/requires/actions?query=workflow%3ATest)
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
A tiny convenience function to require all ruby files in a directory.
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
## Install
|
|
10
9
|
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
requires 'any_file', 'with/or/without/extension.rb'
|
|
14
|
-
|
|
15
|
-
# ...require directories
|
|
16
|
-
requires 'first/directory', 'second-directory'
|
|
17
|
-
|
|
18
|
-
# ...require with a glob
|
|
19
|
-
requires 'base_*', 'directory/*_base'
|
|
20
|
-
|
|
21
|
-
# ...require any other library
|
|
22
|
-
requires 'yaml', 'lib/important', 'lib'
|
|
10
|
+
```bash
|
|
11
|
+
$ gem install requires
|
|
23
12
|
```
|
|
24
13
|
|
|
25
|
-
|
|
14
|
+
## Usage
|
|
26
15
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
--------------------------------------------------
|
|
16
|
+
```ruby
|
|
17
|
+
# Require a directory (recursively)
|
|
18
|
+
require 'requires'
|
|
19
|
+
requires 'lib'
|
|
32
20
|
|
|
33
|
-
|
|
21
|
+
# Individual files can also be loaded (with or without extension)
|
|
22
|
+
requires 'lib/base'
|
|
23
|
+
requires 'lib/base.rb'
|
|
34
24
|
|
|
25
|
+
# ...as well as external gems or built in libraries
|
|
26
|
+
requires 'yaml'
|
|
27
|
+
```
|
|
35
28
|
|
|
29
|
+
All paths are relative to the location of the file that calls `reuiqres`.
|
data/lib/requires.rb
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
def requires(
|
|
2
|
-
|
|
1
|
+
def requires(item)
|
|
2
|
+
base_path = caller_locations(1..1).first.path
|
|
3
|
+
base_dir = File.dirname base_path
|
|
4
|
+
path = File.expand_path item, base_dir
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Dir.chdir base_dir do
|
|
8
|
-
items.each do |item|
|
|
9
|
-
if item.include? '*'
|
|
10
|
-
item += ".rb" unless item.end_with? '.rb'
|
|
11
|
-
Dir["#{item}"].sort.each { |file| require "./#{file}" }
|
|
12
|
-
elsif File.directory? item
|
|
13
|
-
Dir["#{item}/**/*.rb"].sort.each { |file| require "./#{file}" }
|
|
14
|
-
elsif File.file? "#{item}.rb" or File.file? item
|
|
15
|
-
require "./#{item}"
|
|
16
|
-
else
|
|
17
|
-
require item
|
|
18
|
-
end
|
|
6
|
+
if File.directory? path
|
|
7
|
+
Dir["#{path}/**/*.rb"].sort.each do |file|
|
|
8
|
+
require file
|
|
19
9
|
end
|
|
10
|
+
|
|
11
|
+
elsif File.file?("#{path}.rb") || File.file?(path.to_s)
|
|
12
|
+
require path
|
|
13
|
+
|
|
14
|
+
else
|
|
15
|
+
require item
|
|
16
|
+
|
|
20
17
|
end
|
|
21
18
|
end
|
metadata
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: requires
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Danny Ben Shitrit
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-12-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
|
-
description:
|
|
13
|
+
description: Adds functions that allow requiring a direcotry
|
|
14
14
|
email: db@dannyben.com
|
|
15
15
|
executables: []
|
|
16
16
|
extensions: []
|
|
@@ -21,7 +21,8 @@ files:
|
|
|
21
21
|
homepage: https://github.com/dannyben/requires
|
|
22
22
|
licenses:
|
|
23
23
|
- MIT
|
|
24
|
-
metadata:
|
|
24
|
+
metadata:
|
|
25
|
+
rubygems_mfa_required: 'true'
|
|
25
26
|
post_install_message:
|
|
26
27
|
rdoc_options: []
|
|
27
28
|
require_paths:
|
|
@@ -30,15 +31,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
30
31
|
requirements:
|
|
31
32
|
- - ">="
|
|
32
33
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 2.
|
|
34
|
+
version: 2.6.0
|
|
34
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
36
|
requirements:
|
|
36
37
|
- - ">="
|
|
37
38
|
- !ruby/object:Gem::Version
|
|
38
39
|
version: '0'
|
|
39
40
|
requirements: []
|
|
40
|
-
rubygems_version: 3.0
|
|
41
|
+
rubygems_version: 3.4.0
|
|
41
42
|
signing_key:
|
|
42
43
|
specification_version: 4
|
|
43
|
-
summary:
|
|
44
|
+
summary: Require all files in a directory
|
|
44
45
|
test_files: []
|