therefore 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: cde2ad4b634cd0840fe0f13cc9a4c44a5a5aba39fdaab8a4a06a8d1fa7b1f837
4
- data.tar.gz: fa254e95d0954056d2baefbceb5af4d80b3ee146a4bb814880d64190d7b74632
3
+ metadata.gz: 0d246d3dec40b144695422a6bed485e924ba24c594ecc153dc6ec82603de37ca
4
+ data.tar.gz: c254bcc43eede3650a00593f9d85baf6bdb146c6d7d12fe62eb901844c8af85d
5
5
  SHA512:
6
- metadata.gz: c2bcbbc471d55240369fed7cfac8520cbcc0306608727d0661409955d4391222305f904ed649ffaead4a24a387a093842a64ea0824af6797069746772b72e57b
7
- data.tar.gz: e7e5048347332140a1d1c40e42a11fe35de4044f39f9f75db89e1d80e99f35719e2f3bacec61c4de959fffb195bd7cfb10323ec2bd53e74d5a45303c5cf7930f
6
+ metadata.gz: 913bd179a56a3548f09574a8a4732d127d35683b55a1242b70cebf5199a01af67f9a1514e78e310b60a572df7b4578650414fb3c826d26b29da5412ab9c97876
7
+ data.tar.gz: bc9a8140e5029e302212aec60916b72d63036e7220e3758ebf895ed12dd271a2035b0fbc6ed391689b634ac3e03627f0050c895d85aaee545c10d3a6ad499d99
data/CHANGELOG.md CHANGED
@@ -8,6 +8,12 @@
8
8
  ### Bug fixes
9
9
  )-->
10
10
 
11
+ ## 1.1.0 2026-11-06
12
+
13
+ ### New features
14
+
15
+ - Added `if` and `unless` methods.
16
+
11
17
  ## 1.0.1 2025-02-24
12
18
 
13
19
  ### New features
data/README.md CHANGED
@@ -26,6 +26,8 @@ gem install therefore
26
26
 
27
27
  ## Usage
28
28
 
29
+ ### `therefore` and `otherwise`
30
+
29
31
  `obj.therefore {...}` will invoke the block, yielding `obj` to it, unless `obj` is either `nil` or `false`. If the block is invoked its result is returned, otherwise `obj` is returned:
30
32
 
31
33
  ```ruby
@@ -81,6 +83,30 @@ nil.otherwise.to_a # => [nil]
81
83
  'string'.otherwise.to_a # => []
82
84
  ```
83
85
 
86
+ ### `if` and `unless`
87
+
88
+ Let's consider a regular `if...end` conditional:
89
+
90
+ ```ruby
91
+ if condition
92
+ expression
93
+ end
94
+ ```
95
+
96
+ `therefore` and `otherwise` abstract away the condition, relying on the implicit "is it nil/false?", and use the block for the expression.
97
+
98
+ `if` and `unless` do the opposite: they use the block for the condition, and return the receiver or `nil` depending on the result.
99
+
100
+ ```ruby
101
+ request
102
+ .if(&:open?)
103
+ &.close!
104
+
105
+ # is equivalent to
106
+
107
+ request.close! if request.open?
108
+ ```
109
+
84
110
  ## Version numbers
85
111
 
86
112
  Therefore 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.
@@ -18,4 +18,12 @@ module Kernel
18
18
  end
19
19
  end
20
20
  end
21
+
22
+ def if
23
+ self if yield self
24
+ end
25
+
26
+ def unless
27
+ self unless yield self
28
+ end
21
29
  end
@@ -1,3 +1,3 @@
1
1
  module Therefore
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
data/sig/therefore.rbs CHANGED
@@ -23,4 +23,7 @@ module Kernel
23
23
  def otherwise: () { (self) -> void } -> self
24
24
  | () -> Enumerator[nil]
25
25
  | (untyped) -> untyped
26
+
27
+ def if: () { (self) -> bool } -> self?
28
+ def unless: () { (self) -> bool } -> self?
26
29
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: therefore
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
  - Moku S.r.l.
8
8
  - Riccardo Agatea
9
- autorequire:
10
9
  bindir: exe
11
10
  cert_chain: []
12
- date: 2025-02-24 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Just like each, therefore relies on block semantics, so it's essentially
15
14
  an if conditional with a scope, a closure, and the ability to be chained with other
@@ -40,7 +39,6 @@ metadata:
40
39
  homepage_uri: https://github.com/moku-io/therefore
41
40
  source_code_uri: https://github.com/moku-io/therefore
42
41
  changelog_uri: https://github.com/moku-io/therefore/blob/master/CHANGELOG.md
43
- post_install_message:
44
42
  rdoc_options: []
45
43
  require_paths:
46
44
  - lib
@@ -55,8 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
53
  - !ruby/object:Gem::Version
56
54
  version: '0'
57
55
  requirements: []
58
- rubygems_version: 3.5.22
59
- signing_key:
56
+ rubygems_version: 3.6.7
60
57
  specification_version: 4
61
58
  summary: A simple wrapper for if conditionals, what each is for while loops.
62
59
  test_files: []