requires 0.2.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -24
  3. data/lib/requires.rb +14 -17
  4. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57f35e16c778fa287257e4ea4b2bbaab9b38f02e56c54b21fe9e85045ead97e2
4
- data.tar.gz: 3a744da142ac5de0a32f44504a3459c1111cf4e6b11a0cf3f6de9745b33872d7
3
+ metadata.gz: 4cb5240d4eb6c1a4650aed842aaef7229cf6e1a2ffe4480563aac7a3c29e2011
4
+ data.tar.gz: 9f9c1818cf1a9edf762e9e912f465fd5c6c1424957ddadb3539f24bc30307ec7
5
5
  SHA512:
6
- metadata.gz: e7f8e780f10352145323af0e402935d12ddb31b7a335fcb8ecc4e63d76f40118a53a6d1cd0127edb5aa9d9bdfef39bc20e3589b5e6bf9905b5d4d7d095e5321b
7
- data.tar.gz: 7d4aa0fb6adcf3bf6725d2b78d2798326e3ba0de6ca83ce155a376348bb56c23efd2d163ed948a068f9b44e0dfe39ba2a5db9090c4958449aa14c7e26446a254
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
  [![Gem Version](https://badge.fury.io/rb/requires.svg)](https://badge.fury.io/rb/requires)
5
- [![Build Status](https://travis-ci.com/DannyBen/requires.svg?branch=master)](https://travis-ci.com/DannyBen/requires)
4
+ [![Build Status](https://github.com/DannyBen/requires/workflows/Test/badge.svg)](https://github.com/DannyBen/requires/actions?query=workflow%3ATest)
6
5
 
7
- **Requires** is ruby's missing `require` function.
6
+ A tiny convenience function to require all ruby files in a directory.
8
7
 
9
- It lets you...
8
+ ## Install
10
9
 
11
- ```ruby
12
- # ...require multiple files
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
- Everything is relative to where `requires` is called from.
14
+ ## Usage
26
15
 
27
- ---
28
-
29
-
30
- Installation
31
- --------------------------------------------------
16
+ ```ruby
17
+ # Require a directory (recursively)
18
+ require 'requires'
19
+ requires 'lib'
32
20
 
33
- $ gem install requires
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(*items)
2
- items = ['.'] if items.empty?
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
- calling_script = caller.first.sub(/:\d+.*/, '')
5
- base_dir = File.dirname calling_script
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.2.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: 2020-01-09 00:00:00.000000000 Z
11
+ date: 2022-12-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A simple gem to require them all!
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.3.0
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.3
41
+ rubygems_version: 3.4.0
41
42
  signing_key:
42
43
  specification_version: 4
43
- summary: Ruby's missing require function
44
+ summary: Require all files in a directory
44
45
  test_files: []