sorbet_operation 0.1.1 → 0.1.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/.ruby-version +1 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +55 -50
- data/README.md +10 -15
- data/lib/sorbet_operation/base.rb +2 -2
- data/lib/sorbet_operation/version.rb +1 -1
- data/sorbet_operation.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 017a1b8b0b9b579c8de8e0bebc9360bf28dff6af01daeaf7ff63ecf9eb0eb161
|
4
|
+
data.tar.gz: b53ae934c47c223ef2fff9233a84753ed93cf9b24ca8f888e7f4b42c3b096aa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4febd628a8a8515be2fb12c720300220fea5680016c16bb1b749a1c8fe086a387ee463984d4d1b688c909b2c519bfe5e0d8357348545193a4e6662c0fcb2bebf
|
7
|
+
data.tar.gz: 97e203ebb436e7b8282a00f2bbcf7ac05a56e3857596b229f1ea81ba54e72798b55350617630aca95fe61f9461c731d0b56b09e4d6d523e6339659df86cc49bf
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.3.1
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sorbet_operation (0.1.
|
4
|
+
sorbet_operation (0.1.2)
|
5
5
|
sorbet-runtime (~> 0.5.10741)
|
6
6
|
|
7
7
|
GEM
|
@@ -9,67 +9,71 @@ GEM
|
|
9
9
|
specs:
|
10
10
|
ansi (1.5.0)
|
11
11
|
ast (2.4.2)
|
12
|
-
|
12
|
+
bigdecimal (3.0.0)
|
13
13
|
builder (3.2.4)
|
14
14
|
bundler-audit (0.9.1)
|
15
15
|
bundler (>= 1.2.0, < 3)
|
16
16
|
thor (~> 1.0)
|
17
|
-
diff-lcs (1.5.0)
|
18
17
|
docile (1.4.0)
|
19
18
|
erubi (1.12.0)
|
20
|
-
io-console (0.
|
21
|
-
irb (1.
|
22
|
-
|
23
|
-
|
19
|
+
io-console (0.7.2)
|
20
|
+
irb (1.11.2)
|
21
|
+
rdoc
|
22
|
+
reline (>= 0.4.2)
|
23
|
+
json (2.7.1)
|
24
24
|
language_server-protocol (3.17.0.3)
|
25
|
-
minitest (5.
|
25
|
+
minitest (5.22.2)
|
26
26
|
minitest-reporters (1.6.1)
|
27
27
|
ansi
|
28
28
|
builder
|
29
29
|
minitest (>= 5.0)
|
30
30
|
ruby-progressbar
|
31
31
|
netrc (0.11.0)
|
32
|
-
parallel (1.
|
33
|
-
parser (3.
|
32
|
+
parallel (1.24.0)
|
33
|
+
parser (3.3.0.5)
|
34
34
|
ast (~> 2.4.1)
|
35
35
|
racc
|
36
36
|
prettier_print (1.2.1)
|
37
|
-
|
37
|
+
prism (0.24.0)
|
38
|
+
psych (5.1.2)
|
39
|
+
stringio
|
40
|
+
racc (1.7.3)
|
38
41
|
rainbow (3.1.1)
|
39
|
-
rake (13.0
|
40
|
-
rbi (0.
|
41
|
-
|
42
|
-
parser (>= 3.0.0)
|
42
|
+
rake (13.1.0)
|
43
|
+
rbi (0.1.9)
|
44
|
+
prism (>= 0.18.0, < 0.25)
|
43
45
|
sorbet-runtime (>= 0.5.9204)
|
44
|
-
|
45
|
-
|
46
|
-
|
46
|
+
rdoc (6.6.2)
|
47
|
+
psych (>= 4.0.0)
|
48
|
+
regexp_parser (2.9.0)
|
49
|
+
reline (0.4.2)
|
47
50
|
io-console (~> 0.5)
|
48
|
-
rexml (3.2.
|
49
|
-
|
50
|
-
|
51
|
+
rexml (3.2.8)
|
52
|
+
strscan (>= 3.0.9)
|
53
|
+
rubocop (1.60.2)
|
51
54
|
json (~> 2.3)
|
52
55
|
language_server-protocol (>= 3.17.0)
|
53
56
|
parallel (~> 1.10)
|
54
|
-
parser (>= 3.
|
57
|
+
parser (>= 3.3.0.2)
|
55
58
|
rainbow (>= 2.2.2, < 4.0)
|
56
59
|
regexp_parser (>= 1.8, < 3.0)
|
57
60
|
rexml (>= 3.2.5, < 4.0)
|
58
|
-
rubocop-ast (>= 1.
|
61
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
59
62
|
ruby-progressbar (~> 1.7)
|
60
63
|
unicode-display_width (>= 2.4.0, < 3.0)
|
61
|
-
rubocop-ast (1.
|
64
|
+
rubocop-ast (1.30.0)
|
62
65
|
parser (>= 3.2.1.0)
|
63
|
-
rubocop-minitest (0.
|
66
|
+
rubocop-minitest (0.34.5)
|
64
67
|
rubocop (>= 1.39, < 2.0)
|
65
|
-
|
66
|
-
|
67
|
-
rubocop
|
68
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
69
|
+
rubocop-performance (1.20.2)
|
70
|
+
rubocop (>= 1.48.1, < 2.0)
|
71
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
68
72
|
rubocop-rake (0.6.0)
|
69
73
|
rubocop (~> 1.0)
|
70
|
-
rubocop-shopify (2.
|
74
|
+
rubocop-shopify (2.15.1)
|
71
75
|
rubocop (~> 1.51)
|
72
|
-
rubocop-sorbet (0.7.
|
76
|
+
rubocop-sorbet (0.7.7)
|
73
77
|
rubocop (>= 0.90.0)
|
74
78
|
ruby-progressbar (1.13.0)
|
75
79
|
simplecov (0.22.0)
|
@@ -78,45 +82,46 @@ GEM
|
|
78
82
|
simplecov_json_formatter (~> 0.1)
|
79
83
|
simplecov-html (0.12.3)
|
80
84
|
simplecov_json_formatter (0.1.4)
|
81
|
-
sorbet (0.5.
|
82
|
-
sorbet-static (= 0.5.
|
83
|
-
sorbet-runtime (0.5.
|
84
|
-
sorbet-static (0.5.
|
85
|
-
sorbet-static (0.5.
|
86
|
-
sorbet-static-and-runtime (0.5.
|
87
|
-
sorbet (= 0.5.
|
88
|
-
sorbet-runtime (= 0.5.
|
89
|
-
spoom (1.2.
|
85
|
+
sorbet (0.5.11267)
|
86
|
+
sorbet-static (= 0.5.11267)
|
87
|
+
sorbet-runtime (0.5.11267)
|
88
|
+
sorbet-static (0.5.11267-universal-darwin)
|
89
|
+
sorbet-static (0.5.11267-x86_64-linux)
|
90
|
+
sorbet-static-and-runtime (0.5.11267)
|
91
|
+
sorbet (= 0.5.11267)
|
92
|
+
sorbet-runtime (= 0.5.11267)
|
93
|
+
spoom (1.2.4)
|
90
94
|
erubi (>= 1.10.0)
|
91
95
|
sorbet-static-and-runtime (>= 0.5.10187)
|
92
96
|
syntax_tree (>= 6.1.1)
|
93
97
|
thor (>= 0.19.2)
|
94
|
-
|
98
|
+
stringio (3.1.0)
|
99
|
+
strscan (3.1.0)
|
100
|
+
syntax_tree (6.2.0)
|
95
101
|
prettier_print (>= 1.2.0)
|
96
|
-
tapioca (0.
|
102
|
+
tapioca (0.12.0)
|
97
103
|
bundler (>= 2.2.25)
|
98
104
|
netrc (>= 0.11.0)
|
99
105
|
parallel (>= 1.21.0)
|
100
|
-
rbi (
|
101
|
-
sorbet-static-and-runtime (>= 0.5.
|
106
|
+
rbi (>= 0.1.4, < 0.2)
|
107
|
+
sorbet-static-and-runtime (>= 0.5.10820)
|
102
108
|
spoom (~> 1.2.0, >= 1.2.0)
|
103
109
|
thor (>= 1.2.0)
|
104
110
|
yard-sorbet
|
105
|
-
thor (1.
|
106
|
-
unicode-display_width (2.
|
107
|
-
|
108
|
-
diff-lcs (~> 1.3)
|
109
|
-
parser (>= 3.2.0)
|
110
|
-
yard (0.9.34)
|
111
|
+
thor (1.3.0)
|
112
|
+
unicode-display_width (2.5.0)
|
113
|
+
yard (0.9.36)
|
111
114
|
yard-sorbet (0.8.1)
|
112
115
|
sorbet-runtime (>= 0.5)
|
113
116
|
yard (>= 0.9)
|
114
117
|
|
115
118
|
PLATFORMS
|
116
119
|
arm64-darwin-22
|
120
|
+
arm64-darwin-23
|
117
121
|
x86_64-linux
|
118
122
|
|
119
123
|
DEPENDENCIES
|
124
|
+
bigdecimal
|
120
125
|
bundler-audit
|
121
126
|
irb
|
122
127
|
minitest (~> 5.0)
|
@@ -136,4 +141,4 @@ DEPENDENCIES
|
|
136
141
|
yard-sorbet
|
137
142
|
|
138
143
|
BUNDLED WITH
|
139
|
-
2.
|
144
|
+
2.5.9
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# sorbet_operation
|
2
2
|
|
3
3
|
[](https://github.com/thatch-health/sorbet_operation/actions?query=branch%3Amain)
|
4
|
+
[](https://rubygems.org/gems/sorbet_operation)
|
5
|
+
[](https://thatch-health.github.io/sorbet_operation/)
|
4
6
|
|
5
7
|
sorbet_operation is a minimal operation framework that leverages Sorbet's type system to ensure that operations are well-typed and that their inputs and outputs are well-defined.
|
6
8
|
|
@@ -16,7 +18,7 @@ class CreateUser < SorbetOperation::Base
|
|
16
18
|
@user_params = user_params
|
17
19
|
end
|
18
20
|
|
19
|
-
|
21
|
+
private
|
20
22
|
|
21
23
|
sig { returns(ValueType) }
|
22
24
|
def execute
|
@@ -38,7 +40,7 @@ class UsersController < ApplicationController
|
|
38
40
|
redirect_to user
|
39
41
|
else
|
40
42
|
error = result.unwrap_error!
|
41
|
-
T.reveal_type(error) # `SorbetOperation::
|
43
|
+
T.reveal_type(error) # `SorbetOperation::Failure`
|
42
44
|
render :new, alert: error.message
|
43
45
|
end
|
44
46
|
end
|
@@ -51,24 +53,17 @@ class UsersController < ApplicationController
|
|
51
53
|
end
|
52
54
|
```
|
53
55
|
|
54
|
-
Operations return a result object which indicates whether the operation was successful or not. The result object wraps the return value of the operation if it was successful, or an instance of `SorbetOperation::
|
56
|
+
Operations return a result object which indicates whether the operation was successful or not. The result object wraps the return value of the operation if it was successful, or an instance of `SorbetOperation::Failure` if it failed.
|
55
57
|
|
56
58
|
## Installation
|
57
59
|
|
58
|
-
This gem is not yet published to RubyGems.org. For now, you can install it by adding the following to your `Gemfile`:
|
59
|
-
```ruby
|
60
|
-
gem "sorbet_operation", github: "thatch-health/sorbet_operation", branch: "main"
|
61
|
-
```
|
62
|
-
|
63
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
64
|
-
|
65
60
|
Install the gem and add to the application's Gemfile by executing:
|
66
61
|
|
67
|
-
$ bundle add
|
62
|
+
$ bundle add sorbet_operation
|
68
63
|
|
69
64
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
70
65
|
|
71
|
-
$ gem install
|
66
|
+
$ gem install sorbet_operation
|
72
67
|
|
73
68
|
## Usage
|
74
69
|
|
@@ -76,15 +71,15 @@ An operation is a Ruby class that derives from `SorbetOperation::Base`. `SorbetO
|
|
76
71
|
1. define the return type using the `ValueType` generic type member
|
77
72
|
2. define an `#execute` method that returns a `ValueType`
|
78
73
|
|
79
|
-
The `#execute` method should be `
|
74
|
+
The `#execute` method should be `private`, since it is not meant to be invoked directly; rather, operation callers should use the `#perform` public method to actually perform the operation. (Unfortunately, at this time there is no mechanism to enforce that `#execute` is not a public method on child classes, so it's up to the programmer to be vigilant.)
|
80
75
|
|
81
76
|
The `#execute` method does not take any arguments. Most operations require one or more input values. Input values should be passed to the `#initialize` constructor method and stored as instance variables, which can then be accessed from the `#execute` body.
|
82
77
|
|
83
78
|
There are two possible outcomes for an operation:
|
84
79
|
1. if `#execute` returns an instance of `ValueType`, then the operation result is a success
|
85
|
-
2. if `#execute` raises a `SorbetOperation::
|
80
|
+
2. if `#execute` raises a `SorbetOperation::Failure`, then the operation result is a failure
|
86
81
|
|
87
|
-
Exceptions that are not an instance of `SorbetOperation::
|
82
|
+
Exceptions that are not an instance of `SorbetOperation::Failure` will not be caught by the framework and will be propagated to the operation callsite.
|
88
83
|
|
89
84
|
### Using results
|
90
85
|
|
@@ -57,7 +57,7 @@ module SorbetOperation
|
|
57
57
|
sig { params(logger: ::Logger).void }
|
58
58
|
attr_writer :logger
|
59
59
|
|
60
|
-
|
60
|
+
private
|
61
61
|
|
62
62
|
# Implement this method in subclasses to perform the operation.
|
63
63
|
#
|
@@ -70,7 +70,7 @@ module SorbetOperation
|
|
70
70
|
# exception. The exception will not be caught and will be propagated to
|
71
71
|
# the caller.
|
72
72
|
#
|
73
|
-
# This method should be declared as `
|
73
|
+
# This method should be declared as `private` in subclasses to prevent
|
74
74
|
# callers from calling it directly. Callers should instead call {#perform}
|
75
75
|
# to perform the operation and get the result.
|
76
76
|
sig { abstract.returns(ValueType) }
|
data/sorbet_operation.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["sorbet-operation@thatch.ai"]
|
10
10
|
|
11
11
|
spec.summary = "Sorbet-powered operation framework."
|
12
|
-
spec.description = "sorbet_operation is a minimal operation framework that leverages Sorbet's type system to "\
|
12
|
+
spec.description = "sorbet_operation is a minimal operation framework that leverages Sorbet's type system to " \
|
13
13
|
"ensure that operations are well-typed and that their inputs and outputs are well-defined."
|
14
14
|
spec.homepage = "https://github.com/thatch-health/sorbet_operation"
|
15
15
|
spec.license = "MIT"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sorbet_operation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thatch Health, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sorbet-runtime
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
|
-
rubygems_version: 3.
|
73
|
+
rubygems_version: 3.5.9
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
76
|
summary: Sorbet-powered operation framework.
|