requires 1.0.1 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cb5240d4eb6c1a4650aed842aaef7229cf6e1a2ffe4480563aac7a3c29e2011
4
- data.tar.gz: 9f9c1818cf1a9edf762e9e912f465fd5c6c1424957ddadb3539f24bc30307ec7
3
+ metadata.gz: 1b0b0f2f8e0b604e3f3061b95a695fe537a0c7286c2d4cfea8a27578ec828019
4
+ data.tar.gz: 60ecc91cb37fb1a90baaed74fcc911f7644cb6195fab02279a39e1608b6dada7
5
5
  SHA512:
6
- metadata.gz: fc5ac89b618747966124f1c04ed79eeb3f4fa8a5563b31a72dd184e413c81ff17dab041c297ae66df7a77a2954872bf51a05d2fdb8f6a807aebf657cf3affbe6
7
- data.tar.gz: 5d8249cdb56962d0c7fd53d97cd66792e9d1c923cb0b7b0c2732d109b3c46e292bb2e1a3defb412e0c198f0eafbf6b9f116b30f051351e61e4b0e5b13defe53d
6
+ metadata.gz: 4d58d1cb6fe90169fe7fae10fac2a7c5c7af8394544b21d3b488d6277012f00dc85e8dee880a1d49c3ac826e144be237bb5cf2d46bbb11953f6e4eb54d11a6af
7
+ data.tar.gz: 5af9b748b2bff2349b798e9cc60f2ad43eee55c546dc93b9bc0089b5ce1073fc832c87bb1e15e040d24d1de0392ddf794c02bb89da0936d9e728a2734e2138dc
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/requires.svg)](https://badge.fury.io/rb/requires)
4
4
  [![Build Status](https://github.com/DannyBen/requires/workflows/Test/badge.svg)](https://github.com/DannyBen/requires/actions?query=workflow%3ATest)
5
5
 
6
- A tiny convenience function to require all ruby files in a directory.
6
+ A tiny convenience function to require or autoload all ruby files in a directory.
7
7
 
8
8
  ## Install
9
9
 
@@ -13,6 +13,8 @@ $ gem install requires
13
13
 
14
14
  ## Usage
15
15
 
16
+ ### `requires`
17
+
16
18
  ```ruby
17
19
  # Require a directory (recursively)
18
20
  require 'requires'
@@ -26,4 +28,30 @@ requires 'lib/base.rb'
26
28
  requires 'yaml'
27
29
  ```
28
30
 
29
- All paths are relative to the location of the file that calls `reuiqres`.
31
+ All paths are relative to the location of the file that calls `requires`.
32
+
33
+ ### `autoloads`
34
+
35
+ Autoload en masse, with paths relative to the one calling `autuoloads`.
36
+
37
+ ```ruby
38
+ require 'requires'
39
+ autoloads 'lib', %i[Asset SomeAPI HTTPClient]
40
+ ```
41
+
42
+ which is equivalent to these native autoload statements:
43
+
44
+ ```ruby
45
+ autoload :Asset, './lib/asset'
46
+ autoload :SomeAPI, './lib/some_api'
47
+ autoload :HTTPClient, './lib/HTTPClient'
48
+ ```
49
+
50
+ In case you wish to autoload from the same directory, you can omit the first
51
+ argument:
52
+
53
+ ```ruby
54
+ autoloads %i[Asset SomeAPI HTTPClient]
55
+ # which is the same as
56
+ # autoloads '.', %i[Asset SomeAPI HTTPClient]
57
+ ```
@@ -0,0 +1 @@
1
+ VERSION = '1.1.0'
data/lib/requires.rb CHANGED
@@ -4,7 +4,7 @@ def requires(item)
4
4
  path = File.expand_path item, base_dir
5
5
 
6
6
  if File.directory? path
7
- Dir["#{path}/**/*.rb"].sort.each do |file|
7
+ Dir["#{path}/**/*.rb"].each do |file|
8
8
  require file
9
9
  end
10
10
 
@@ -16,3 +16,23 @@ def requires(item)
16
16
 
17
17
  end
18
18
  end
19
+
20
+ def autoloads(base, symbols = nil)
21
+ unless symbols
22
+ symbols = base
23
+ base = '.'
24
+ end
25
+
26
+ base_path = caller_locations(1..1).first.path
27
+ base_dir = File.dirname base_path
28
+ path = File.expand_path base, base_dir
29
+
30
+ symbols.each do |symbol|
31
+ file = symbol.to_s
32
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') # Break consecutive uppercase letters before the last capital
33
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2') # Break lowercase or digits before an uppercase letter
34
+ .downcase
35
+
36
+ autoload symbol, "#{path}/#{file}"
37
+ end
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: requires
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-29 00:00:00.000000000 Z
11
+ date: 2024-07-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Adds functions that allow requiring a direcotry
14
14
  email: db@dannyben.com
@@ -18,12 +18,17 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - README.md
20
20
  - lib/requires.rb
21
+ - lib/requires/version.rb
21
22
  homepage: https://github.com/dannyben/requires
22
23
  licenses:
23
24
  - MIT
24
25
  metadata:
26
+ bug_tracker_uri: https://github.com/DannyBen/requires/issues
27
+ changelog_uri: https://github.com/DannyBen/requires/blob/master/CHANGELOG.md
28
+ homepage_uri: https://requires.dannyb.co/
29
+ source_code_uri: https://github.com/DannyBen/requires
25
30
  rubygems_mfa_required: 'true'
26
- post_install_message:
31
+ post_install_message:
27
32
  rdoc_options: []
28
33
  require_paths:
29
34
  - lib
@@ -31,15 +36,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
31
36
  requirements:
32
37
  - - ">="
33
38
  - !ruby/object:Gem::Version
34
- version: 2.6.0
39
+ version: '3.0'
35
40
  required_rubygems_version: !ruby/object:Gem::Requirement
36
41
  requirements:
37
42
  - - ">="
38
43
  - !ruby/object:Gem::Version
39
44
  version: '0'
40
45
  requirements: []
41
- rubygems_version: 3.4.0
42
- signing_key:
46
+ rubygems_version: 3.5.14
47
+ signing_key:
43
48
  specification_version: 4
44
49
  summary: Require all files in a directory
45
50
  test_files: []