therefore 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 +20 -0
- data/README.md +26 -0
- data/Rakefile +0 -3
- data/lib/therefore/kernel_patch.rb +8 -0
- data/lib/therefore/version.rb +1 -1
- data/sig/therefore.rbs +29 -0
- data/therefore.gemspec +30 -0
- metadata +5 -7
- data/.rspec +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0d246d3dec40b144695422a6bed485e924ba24c594ecc153dc6ec82603de37ca
|
|
4
|
+
data.tar.gz: c254bcc43eede3650a00593f9d85baf6bdb146c6d7d12fe62eb901844c8af85d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 913bd179a56a3548f09574a8a4732d127d35683b55a1242b70cebf5199a01af67f9a1514e78e310b60a572df7b4578650414fb3c826d26b29da5412ab9c97876
|
|
7
|
+
data.tar.gz: bc9a8140e5029e302212aec60916b72d63036e7220e3758ebf895ed12dd271a2035b0fbc6ed391689b634ac3e03627f0050c895d85aaee545c10d3a6ad499d99
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
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 2026-11-06
|
|
12
|
+
|
|
13
|
+
### New features
|
|
14
|
+
|
|
15
|
+
- Added `if` and `unless` methods.
|
|
16
|
+
|
|
17
|
+
## 1.0.1 2025-02-24
|
|
18
|
+
|
|
19
|
+
### New features
|
|
20
|
+
|
|
21
|
+
- Added type signatures for the methods.
|
|
22
|
+
|
|
3
23
|
## 1.0.0 2023-05-04
|
|
4
24
|
|
|
5
25
|
First release. Refer to [README.md](README.md) for the full documentation.
|
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.
|
data/Rakefile
CHANGED
data/lib/therefore/version.rb
CHANGED
data/sig/therefore.rbs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class NilClass
|
|
2
|
+
def therefore: () { (self) -> void } -> self
|
|
3
|
+
| () -> Enumerator[nil]
|
|
4
|
+
|
|
5
|
+
def otherwise: [T] () { (self) -> T } -> T
|
|
6
|
+
| () -> Enumerator[class]
|
|
7
|
+
| (untyped) -> untyped
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class FalseClass
|
|
11
|
+
def therefore: () { (self) -> void } -> self
|
|
12
|
+
| () -> Enumerator[nil]
|
|
13
|
+
|
|
14
|
+
def otherwise: [T] () { (self) -> T } -> T
|
|
15
|
+
| () -> Enumerator[class]
|
|
16
|
+
| (untyped) -> untyped
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module Kernel
|
|
20
|
+
def therefore: [T] () { (self) -> T } -> T
|
|
21
|
+
| () -> Enumerator[self]
|
|
22
|
+
|
|
23
|
+
def otherwise: () { (self) -> void } -> self
|
|
24
|
+
| () -> Enumerator[nil]
|
|
25
|
+
| (untyped) -> untyped
|
|
26
|
+
|
|
27
|
+
def if: () { (self) -> bool } -> self?
|
|
28
|
+
def unless: () { (self) -> bool } -> self?
|
|
29
|
+
end
|
data/therefore.gemspec
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require_relative 'lib/therefore/version'
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = 'therefore'
|
|
5
|
+
spec.version = Therefore::VERSION
|
|
6
|
+
spec.authors = ['Moku S.r.l.', 'Riccardo Agatea']
|
|
7
|
+
spec.email = ['info@moku.io']
|
|
8
|
+
spec.license = 'MIT'
|
|
9
|
+
|
|
10
|
+
spec.summary = 'A simple wrapper for if conditionals, what each is for while loops.'
|
|
11
|
+
spec.description = "Just like each, therefore relies on block semantics, so it's essentially an if " \
|
|
12
|
+
'conditional with a scope, a closure, and the ability to be chained with other methods.'
|
|
13
|
+
spec.homepage = 'https://github.com/moku-io/therefore'
|
|
14
|
+
spec.required_ruby_version = '>= 2.6.0'
|
|
15
|
+
|
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/moku-io/therefore'
|
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/moku-io/therefore/blob/master/CHANGELOG.md'
|
|
19
|
+
|
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
22
|
+
spec.files = Dir.chdir __dir__ do
|
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
24
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
spec.bindir = 'exe'
|
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
29
|
+
spec.require_paths = ['lib']
|
|
30
|
+
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.
|
|
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:
|
|
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
|
|
@@ -20,7 +19,6 @@ executables: []
|
|
|
20
19
|
extensions: []
|
|
21
20
|
extra_rdoc_files: []
|
|
22
21
|
files:
|
|
23
|
-
- ".rspec"
|
|
24
22
|
- ".rubocop.yml"
|
|
25
23
|
- CHANGELOG.md
|
|
26
24
|
- Gemfile
|
|
@@ -32,6 +30,8 @@ files:
|
|
|
32
30
|
- lib/therefore/kernel_patch.rb
|
|
33
31
|
- lib/therefore/nil_class_patch.rb
|
|
34
32
|
- lib/therefore/version.rb
|
|
33
|
+
- sig/therefore.rbs
|
|
34
|
+
- therefore.gemspec
|
|
35
35
|
homepage: https://github.com/moku-io/therefore
|
|
36
36
|
licenses:
|
|
37
37
|
- MIT
|
|
@@ -39,7 +39,6 @@ metadata:
|
|
|
39
39
|
homepage_uri: https://github.com/moku-io/therefore
|
|
40
40
|
source_code_uri: https://github.com/moku-io/therefore
|
|
41
41
|
changelog_uri: https://github.com/moku-io/therefore/blob/master/CHANGELOG.md
|
|
42
|
-
post_install_message:
|
|
43
42
|
rdoc_options: []
|
|
44
43
|
require_paths:
|
|
45
44
|
- lib
|
|
@@ -54,8 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
54
53
|
- !ruby/object:Gem::Version
|
|
55
54
|
version: '0'
|
|
56
55
|
requirements: []
|
|
57
|
-
rubygems_version: 3.
|
|
58
|
-
signing_key:
|
|
56
|
+
rubygems_version: 3.6.7
|
|
59
57
|
specification_version: 4
|
|
60
58
|
summary: A simple wrapper for if conditionals, what each is for while loops.
|
|
61
59
|
test_files: []
|
data/.rspec
DELETED