include_all 0.0.1 → 0.0.2
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 +21 -0
- data/include_all.gemspec +1 -1
- data/lib/include_all.rb +19 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1998f5fa8a2ff35ee7bc685f8bda4bf27713d97f6626387e4c6527fcbede18a
|
4
|
+
data.tar.gz: 80b4cfc142c4c613d7d42e5ace879436a907a5f9340168b4b2765bf591e05457
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06cd0207b09f3a9ec8142e49cee00acd05287da925cace67090d410bbaf16bac1b20e9dc1d912b4e0614632747796aa23e13c341122e9ec62f6832668f6030d4
|
7
|
+
data.tar.gz: 8289477d2a974545911844ce4417520ac6ef740915e248c88c4179dd22d466bdf0e10ed4dda809f2b0a12d8309a9b0038b416703e87b5ba56efb804dcbfb15eb
|
data/README.md
CHANGED
@@ -1 +1,22 @@
|
|
1
1
|
# `include_all`
|
2
|
+
|
3
|
+
You've heard of [`require_all`](https://github.com/jarmo/require_all), now meet `include_all`! Written
|
4
|
+
for the purpose of including functions from a `require`'d module without typing them all out, this niche,
|
5
|
+
but personally useful, gem shines brightest when used in conjunction with a Ruby monolith.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
`gem install 'include_all'` or include in your `Gemfile`: `gem 'include_all'`
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
It's best used after something that has a lot of items you'd like to include but not do so individually.
|
14
|
+
Let's assume that the `methods` module has a bunch of stuff we'd like to bring in.
|
15
|
+
```ruby
|
16
|
+
require 'require_all`
|
17
|
+
require 'include_all`
|
18
|
+
|
19
|
+
require 'methods'
|
20
|
+
include_all
|
21
|
+
```
|
22
|
+
The `include_all` gem will automatically _diff_ the list of `require`d objects and figure out what's missing.
|
data/include_all.gemspec
CHANGED
data/lib/include_all.rb
CHANGED
@@ -1,13 +1,29 @@
|
|
1
1
|
# Implmentation of approach described by this SO article:
|
2
2
|
# https://stackoverflow.com/questions/3084325/getting-contents-classes-modules-of-required-files-in-ruby
|
3
3
|
|
4
|
+
# Module declaration
|
4
5
|
module IncludeAll
|
6
|
+
# Include all (in the future, a subset) of functionality or
|
7
|
+
# classes in a newly-required module
|
8
|
+
#
|
9
|
+
# Example
|
10
|
+
# require_all 'module'
|
11
|
+
# include_all
|
5
12
|
|
6
13
|
def include_all(*args)
|
7
14
|
added = list_objects()
|
8
|
-
|
15
|
+
(added - $startup).each {
|
16
|
+
|m|
|
17
|
+
begin
|
18
|
+
include m
|
19
|
+
rescue TypeError => e
|
20
|
+
# Do nothing
|
21
|
+
end
|
22
|
+
}
|
23
|
+
$startup = added
|
9
24
|
end
|
10
25
|
|
26
|
+
# Lists objects in the ObjectSpace on demand
|
11
27
|
def list_objects
|
12
28
|
ObjectSpace.each_object(Module).to_a
|
13
29
|
end
|
@@ -15,4 +31,6 @@ module IncludeAll
|
|
15
31
|
end
|
16
32
|
|
17
33
|
include IncludeAll
|
34
|
+
|
35
|
+
# Create initial conditions at import
|
18
36
|
$startup = IncludeAll.list_objects()
|