bountiful_blocks 1.0.0 → 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 +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +13 -0
- data/lib/bountiful_blocks/multiblock.rb +23 -4
- data/lib/bountiful_blocks/version.rb +1 -1
- data/lib/bountiful_blocks.rb +0 -4
- data/sig/lib/bountiful_blocks/kernel_patch.rbs +3 -0
- data/sig/lib/bountiful_blocks/multiblock.rbs +9 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 107bca67d5b0f9fe089a8e67a701d349262fb64941d56b0cf8a721d0d99f0512
|
4
|
+
data.tar.gz: 17bc58e18db0cdff78e8bcfe32b7bd4cb51d3b385a79a65d2cb0c40d4edac69b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f53522d03a12b7b0aaa9ddd0536de017657ee4534da05c059a4248004bfe6f940e3437ffaee03af7641c7e9b43596818ae0d796fcff377e50444528331146628
|
7
|
+
data.tar.gz: 8ecaca17d07af11ed7bd3cf31ace24d9cb808f40b6249d65bb21f4af0ee631ee9301658de034c05807d6f9a18b38c9f918ae4b57acf0eb651a940c604aac8e95
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
<!--[//]: # (
|
4
|
+
## <Release number> <Date YYYY-MM-DD>
|
5
|
+
### Breaking changes
|
6
|
+
### Deprecations
|
7
|
+
### New features
|
8
|
+
### Bug fixes
|
9
|
+
)-->
|
10
|
+
|
11
|
+
## 1.1.0 2023-09-07
|
12
|
+
|
13
|
+
### New features
|
14
|
+
|
15
|
+
- Added `raw!`, `given!`, and `call_all!` utility methods.
|
16
|
+
- Now multiblocks are always frozen after construction.
|
17
|
+
- Added RBS type signatures.
|
18
|
+
|
19
|
+
### Bug fixes
|
20
|
+
|
21
|
+
- Fixed enforcing of block names limitations.
|
22
|
+
- Removed the `Error` class.
|
23
|
+
|
3
24
|
## 1.0.0 2023-05-30
|
4
25
|
|
5
26
|
First release. Refer to [README.md](README.md) for the full documentation.
|
data/README.md
CHANGED
@@ -94,6 +94,19 @@ def deliver message, &block
|
|
94
94
|
end
|
95
95
|
```
|
96
96
|
|
97
|
+
### Names
|
98
|
+
|
99
|
+
Block names follow the same rules as method names, with the exception that they can't end in `!`, `?`, or `=`.
|
100
|
+
|
101
|
+
### Utility methods
|
102
|
+
|
103
|
+
To avoid conflicts, all utility method names will end in either `!`, `?`, or `=`.
|
104
|
+
|
105
|
+
- `raw!` returns the value returned by the block, which can be useful to allow a block to work both as a regular block and a multiblock.
|
106
|
+
- `given?(name)` returns `true` if a block named `name` was provided.
|
107
|
+
- `given!` returns the names of all the provided blocks.
|
108
|
+
- `call_all!` returns a Hash that maps all block names to their results. Notice that since multiblocks are frozen, `call_all!` can't cache the Hash and must create a new one on every invocation.
|
109
|
+
|
97
110
|
## Version numbers
|
98
111
|
|
99
112
|
BountifulBlocks loosely follows [Semantic Versioning](https://semver.org/), with a hard guarantee that breaking changes to the public API will always coincide with an increase to the `MAJOR` number.
|
@@ -1,22 +1,27 @@
|
|
1
1
|
module BountifulBlocks
|
2
2
|
class Multiblock
|
3
3
|
def initialize *required_blocks, &block
|
4
|
-
instance_exec(&block)
|
4
|
+
@raw = instance_exec(&block)
|
5
5
|
|
6
6
|
missing_blocks = required_blocks.reject { |method_name| given? method_name }
|
7
7
|
|
8
8
|
raise ArgumentError, "Block required for #{missing_blocks.join ', '}" unless missing_blocks.empty?
|
9
|
+
|
10
|
+
given!.freeze
|
11
|
+
freeze
|
9
12
|
end
|
10
13
|
|
11
14
|
def method_missing(name, *args, **kwargs, &block)
|
12
|
-
super unless args.empty? && kwargs.empty?
|
13
|
-
super if name.end_with? '!', '?', '='
|
15
|
+
return super unless args.empty? && kwargs.empty?
|
16
|
+
return super if name.end_with? '!', '?', '='
|
14
17
|
|
15
18
|
define_singleton_method name, &block
|
19
|
+
|
20
|
+
nil
|
16
21
|
end
|
17
22
|
|
18
23
|
def respond_to_missing?(name, *args, **kwargs, &block)
|
19
|
-
super if name.end_with? '!', '?', '='
|
24
|
+
return super if name.end_with? '!', '?', '='
|
20
25
|
|
21
26
|
true
|
22
27
|
end
|
@@ -24,5 +29,19 @@ module BountifulBlocks
|
|
24
29
|
def given? name
|
25
30
|
singleton_class.method_defined? name
|
26
31
|
end
|
32
|
+
|
33
|
+
def given!
|
34
|
+
@given = [] unless defined?(@given)
|
35
|
+
|
36
|
+
@given
|
37
|
+
end
|
38
|
+
|
39
|
+
def raw!
|
40
|
+
@raw
|
41
|
+
end
|
42
|
+
|
43
|
+
def call_all!
|
44
|
+
given!.to_h { |name| [name, public_send(name)] }
|
45
|
+
end
|
27
46
|
end
|
28
47
|
end
|
data/lib/bountiful_blocks.rb
CHANGED
@@ -0,0 +1,9 @@
|
|
1
|
+
module BountifulBlocks
|
2
|
+
class Multiblock
|
3
|
+
def initialize: (*Symbol required_blocks) { () -> untyped } -> void
|
4
|
+
def given?: (Symbol name) -> bool
|
5
|
+
def given!: () -> Array[Symbol]
|
6
|
+
def raw!: () -> untyped
|
7
|
+
def call_all!: () -> Hash[Symbol, untyped]
|
8
|
+
end
|
9
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bountiful_blocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moku S.r.l.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-09-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A simple and idiomatic way to pass multiple blocks to a method.
|
15
15
|
email:
|
@@ -28,6 +28,8 @@ files:
|
|
28
28
|
- lib/bountiful_blocks/kernel_patch.rb
|
29
29
|
- lib/bountiful_blocks/multiblock.rb
|
30
30
|
- lib/bountiful_blocks/version.rb
|
31
|
+
- sig/lib/bountiful_blocks/kernel_patch.rbs
|
32
|
+
- sig/lib/bountiful_blocks/multiblock.rbs
|
31
33
|
homepage: https://github.com/moku-io/bountiful_blocks
|
32
34
|
licenses:
|
33
35
|
- MIT
|
@@ -50,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
52
|
- !ruby/object:Gem::Version
|
51
53
|
version: '0'
|
52
54
|
requirements: []
|
53
|
-
rubygems_version: 3.
|
55
|
+
rubygems_version: 3.4.6
|
54
56
|
signing_key:
|
55
57
|
specification_version: 4
|
56
58
|
summary: A simple and idiomatic way to pass multiple blocks to a method.
|