modulation 0.18 → 0.19
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/CHANGELOG.md +5 -0
- data/README.md +56 -56
- data/lib/modulation/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 213cf5d64fdb238b965b7c625c0bc513da79cc9866c52c4051c02bc309c93eec
|
4
|
+
data.tar.gz: fffb3da5ee7f10934e6386da7fa01611934ba217ee6df33a6e6d6f7715148352
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11c410d6b8eacff67ba95484189121e7d6488c88e3a2278e4fa6b241f341a17c5dd5a4c281809567e321a6d2933d0fd519685b890eb0419d8db2e4b4aed60a5c
|
7
|
+
data.tar.gz: c0f58c853854d576325b9fdf45b9dba78d69cf8e373807b6d656733fd7d4192673eb3bdf6cb6ccce8b33ae131b3c70ac2f98da1d00fa0625fe2d55fcc686338e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -25,24 +25,6 @@ a functional style, minimizing boilerplate code.
|
|
25
25
|
> Modulation, it is not intended as a comprehensive solution for using
|
26
26
|
> third-party libraries.
|
27
27
|
|
28
|
-
## Features
|
29
|
-
|
30
|
-
- Provides complete isolation of each module: constant definitions in one file
|
31
|
-
do not leak into another.
|
32
|
-
- Enforces explicit exporting and importing of methods, classes, modules and
|
33
|
-
constants.
|
34
|
-
- Supports circular dependencies.
|
35
|
-
- Supports [default exports](#default-exports) for modules exporting a single
|
36
|
-
class or value.
|
37
|
-
- Modules can be [reloaded](#reloading-modules) at runtime without breaking your
|
38
|
-
code in wierd ways.
|
39
|
-
- Modules can be [lazy loaded](#lazy-loading) to improve start up time and
|
40
|
-
memory consumption.
|
41
|
-
- Allows [mocking of dependencies](#mocking-dependencies) for testing purposes.
|
42
|
-
- Can be used to [write gems](#writing-gems-using-modulation).
|
43
|
-
- Facilitates [unit-testing](#unit-testing-modules) of private methods and
|
44
|
-
constants.
|
45
|
-
|
46
28
|
## Rationale
|
47
29
|
|
48
30
|
You're probably asking yourself "what the ****?" , but when your Ruby app grows
|
@@ -83,6 +65,24 @@ are hidden unless explicitly exported, and the global namespace remains
|
|
83
65
|
clutter-free. All dependencies between source files are explicit, visible, and
|
84
66
|
easy to understand.
|
85
67
|
|
68
|
+
## Features
|
69
|
+
|
70
|
+
- Provides complete isolation of each module: constant definitions in one file
|
71
|
+
do not leak into another.
|
72
|
+
- Enforces explicit exporting and importing of methods, classes, modules and
|
73
|
+
constants.
|
74
|
+
- Supports circular dependencies.
|
75
|
+
- Supports [default exports](#default-exports) for modules exporting a single
|
76
|
+
class or value.
|
77
|
+
- Modules can be [lazy loaded](#lazy-loading) to improve start up time and
|
78
|
+
memory consumption.
|
79
|
+
- Modules can be [reloaded](#reloading-modules) at runtime without breaking your
|
80
|
+
code in wierd ways.
|
81
|
+
- Allows [mocking of dependencies](#mocking-dependencies) for testing purposes.
|
82
|
+
- Can be used to [write gems](#writing-gems-using-modulation).
|
83
|
+
- Facilitates [unit-testing](#unit-testing-modules) of private methods and
|
84
|
+
constants.
|
85
|
+
|
86
86
|
## Installing Modulation
|
87
87
|
|
88
88
|
You can install the Modulation as a gem, or add it in your `Gemfile`:
|
@@ -339,6 +339,44 @@ class UserControllerTest < Minitest::Test
|
|
339
339
|
end
|
340
340
|
```
|
341
341
|
|
342
|
+
### Lazy Loading
|
343
|
+
|
344
|
+
Modulation allows the use of lazy-loaded modules - loading of modules only once
|
345
|
+
they're needed by the application, in similar fashion to `Module#auto_load`. To
|
346
|
+
lazy load modules use the `#auto_import` method, which takes a constant name and
|
347
|
+
a path:
|
348
|
+
|
349
|
+
```ruby
|
350
|
+
export :foo
|
351
|
+
|
352
|
+
auto_import :BAR, './bar'
|
353
|
+
|
354
|
+
def foo
|
355
|
+
# the bar module will only be loaded once this method is called
|
356
|
+
MODULE::BAR
|
357
|
+
end
|
358
|
+
```
|
359
|
+
|
360
|
+
> Lazy-loaded constants must always be qualified. When referring to a
|
361
|
+
> lazy-loaded constant from the module's top namespace, use the `MODULE`
|
362
|
+
> namespace, as shown above.
|
363
|
+
|
364
|
+
The `auto_import` method can also take a hash mapping constant names to paths.
|
365
|
+
This is especially useful when multiple concerns are grouped under a single
|
366
|
+
namespace:
|
367
|
+
|
368
|
+
```ruby
|
369
|
+
export_default :SuperNet
|
370
|
+
|
371
|
+
module SuperNet
|
372
|
+
auto_import(
|
373
|
+
HTTP1: './http1',
|
374
|
+
HTTP2: './http2',
|
375
|
+
WebSockets: './websockets'
|
376
|
+
)
|
377
|
+
end
|
378
|
+
```
|
379
|
+
|
342
380
|
### Reloading modules
|
343
381
|
|
344
382
|
Modules can be reloaded at run-time for easy hot code reloading:
|
@@ -379,44 +417,6 @@ settings = import('settings')
|
|
379
417
|
settings = settings.__reload!
|
380
418
|
```
|
381
419
|
|
382
|
-
## Lazy Loading
|
383
|
-
|
384
|
-
Modulation allows the use of lazy-loaded modules - loading of modules only once
|
385
|
-
they're needed by the application, in similar fashion to `Module#auto_load`. To
|
386
|
-
lazy load modules use the `#auto_import` method, which takes a constant name and
|
387
|
-
a path:
|
388
|
-
|
389
|
-
```ruby
|
390
|
-
export :foo
|
391
|
-
|
392
|
-
auto_import :BAR, './bar'
|
393
|
-
|
394
|
-
def foo
|
395
|
-
# the bar module will only be loaded once this method is called
|
396
|
-
MODULE::BAR
|
397
|
-
end
|
398
|
-
```
|
399
|
-
|
400
|
-
> Lazy-loaded constants must always be qualified. When referring to a
|
401
|
-
> lazy-loaded constant from the module's top namespace, use the `MODULE`
|
402
|
-
> namespace, as shown above.
|
403
|
-
|
404
|
-
The `auto_import` method can also take a hash mapping constant names to paths.
|
405
|
-
This is especially useful when multiple concerns are grouped under a single
|
406
|
-
namespace:
|
407
|
-
|
408
|
-
```ruby
|
409
|
-
export_default :SuperNet
|
410
|
-
|
411
|
-
module SuperNet
|
412
|
-
auto_import(
|
413
|
-
HTTP1: './http1',
|
414
|
-
HTTP2: './http2',
|
415
|
-
WebSockets: './websockets'
|
416
|
-
)
|
417
|
-
end
|
418
|
-
```
|
419
|
-
|
420
420
|
## Writing gems using Modulation
|
421
421
|
|
422
422
|
Modulation can be used to write gems, providing fine-grained control over your
|
data/lib/modulation/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modulation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.19'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -61,11 +61,11 @@ files:
|
|
61
61
|
- lib/modulation/module_mixin.rb
|
62
62
|
- lib/modulation/paths.rb
|
63
63
|
- lib/modulation/version.rb
|
64
|
-
homepage: http://github.com/
|
64
|
+
homepage: http://github.com/digital-fabric/modulation
|
65
65
|
licenses:
|
66
66
|
- MIT
|
67
67
|
metadata:
|
68
|
-
source_code_uri: https://github.com/
|
68
|
+
source_code_uri: https://github.com/digital-fabric/modulation
|
69
69
|
post_install_message:
|
70
70
|
rdoc_options:
|
71
71
|
- "--title"
|