dry-monads-sorbet 1.1.0.pre.10 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +34 -6
- data/dry-monads-sorbet.gemspec +6 -0
- data/lib/bundled_rbi/dry-monads.rbi +3 -0
- data/lib/dry-monads-sorbet/tasks/dry_monads_sorbet.rake +5 -3
- data/lib/dry/monads/sorbet/version.rb +1 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79bc66c3eab53916acb4abb65238a4f570b1080e5d3d89b9a10e31e7dc4536c8
|
4
|
+
data.tar.gz: 9a31dcdb58f30b95e49215da0d56ce52a07cdaf55bce20ab74277e55bb496e8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee8019df627a72a37d96b3bc19edceb990922e4b2ed4e495961ae826d1248a9fc004350fb9da7bcf622ebda97d9ed67a570c45625f43efbff2741e0320f4f132
|
7
|
+
data.tar.gz: 1ce9a387e1c3c806e110bf1544f425e04ffbf4495ba8ed3e8e8e028a7bd1163988c80c7751bd28b647e82da9b593a090432791df2ca3197a526ee7e84c4d9ca5
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
![dry-monads-sorbet](https://user-images.githubusercontent.com/2643026/69986703-dfc68200-1535-11ea-9035-38ecbdb67138.png)
|
2
2
|
|
3
|
-
# Dry Monads Sorbet ![CI Badge](https://github.com/tricycle/dry-monads-sorbet/workflows/
|
3
|
+
# Dry Monads Sorbet ![CI Badge](https://github.com/tricycle/dry-monads-sorbet/workflows/Continuous%20Integration/badge.svg)
|
4
4
|
|
5
5
|
Sorbet type hints for Dry::Monads.
|
6
6
|
|
7
|
+
This gem is very small, it opens up the `Dry::Monads::Result` and `Dry::Monads::Maybe` classes to add type members
|
8
|
+
that are subsequently referred to in a bundled `.rbi` file for the `dry-monads` gem.
|
9
|
+
|
10
|
+
The bundled rbi annotations are installed/updated via a rake task included in the gem.
|
11
|
+
|
7
12
|
## Installation
|
8
13
|
|
9
14
|
Add the gem to your Gemfile:
|
@@ -24,7 +29,7 @@ The rake task that copies the bundled `.rbi` files into your project should alre
|
|
24
29
|
bundle exec rake dry_monads_sorbet:update_rbi
|
25
30
|
```
|
26
31
|
|
27
|
-
### Outside of
|
32
|
+
### Outside of Rails projects:
|
28
33
|
|
29
34
|
Include the `Rakefile` in your own projects `Rakefile` to get access to the rbi update command:
|
30
35
|
|
@@ -40,13 +45,36 @@ After including the Rakefile you should then have access to the task as describe
|
|
40
45
|
|
41
46
|
## Usage
|
42
47
|
|
48
|
+
Usage is fairly simple, just annotate your methods as follows:
|
49
|
+
|
43
50
|
```ruby
|
44
51
|
require 'dry/monads/sorbet'
|
45
52
|
|
46
|
-
class
|
53
|
+
class MyLoginService
|
47
54
|
extend T::Sig
|
48
55
|
|
49
|
-
sig{returns(Dry::Monads::Result[StandardError, String])}
|
50
|
-
def
|
51
|
-
|
56
|
+
sig{params(username: String).returns(Dry::Monads::Result[StandardError, String])}
|
57
|
+
def check_username(username)
|
58
|
+
case username
|
59
|
+
when 'samuelgiles93'
|
60
|
+
Dry::Monads::Success('Hi Sam!')
|
61
|
+
else
|
62
|
+
Dry::Monads::Failure(
|
63
|
+
StandardError.new('Unauthorised')
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
sig{params(username: String).returns(Dry::Monads::Maybe[Integer])}
|
69
|
+
def find_fullname(username)
|
70
|
+
case username
|
71
|
+
when 'samuelgiles93'
|
72
|
+
Dry::Monads::Some('Samuel Giles')
|
73
|
+
else
|
74
|
+
Dry::Monads::None()
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
52
78
|
```
|
79
|
+
|
80
|
+
With the type annotations in place you'll get type errors when you attempt to say call a method that doesn't exist on the `Some` of a `Maybe` or the `Success` of a `Result`.
|
data/dry-monads-sorbet.gemspec
CHANGED
@@ -21,6 +21,12 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.bindir = 'exe'
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ['lib']
|
24
|
+
spec.post_install_message = <<~TEXT
|
25
|
+
dry-monads-sorbet has been installed/updated.
|
26
|
+
|
27
|
+
This gem ships with a bundled rbi file that must be copied into your project.
|
28
|
+
You can use the included "dry_monads_sorbet:update_rbi" to do this.
|
29
|
+
TEXT
|
24
30
|
|
25
31
|
spec.add_dependency 'sorbet'
|
26
32
|
spec.add_dependency 'sorbet-runtime'
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# typed: strong
|
2
2
|
#
|
3
|
+
# This rbi file is bundled in the dry-monads-sorbet gem and is copied down
|
4
|
+
# into projects using the dry_monads_sorbet:update_rbi rake task.
|
5
|
+
#
|
3
6
|
# Any changes to the type annotations for Dry::Monads should be made
|
4
7
|
# in the dry-monads-sorbet gem itself in its bundled_rbi directory.
|
5
8
|
|
@@ -1,23 +1,25 @@
|
|
1
1
|
require 'dry-monads-sorbet'
|
2
|
+
require 'pathname'
|
2
3
|
|
3
4
|
DRY_MONADS_SORBET_RAKE_DIR = File.dirname(__FILE__)
|
4
5
|
|
5
6
|
namespace :dry_monads_sorbet do
|
6
|
-
|
7
|
+
desc "Generate rbis for dry/monads"
|
8
|
+
task :update_rbi do
|
7
9
|
FileUtils.rm_rf(dry_monads_sorbet_rbi_path)
|
8
10
|
|
9
11
|
copy_bundled_rbi('dry-monads.rbi')
|
10
12
|
end
|
11
13
|
|
12
14
|
def dry_monads_sorbet_rbi_path
|
13
|
-
Rake.original_dir.join('sorbet', 'dry-monads-sorbet')
|
15
|
+
Pathname.new(Rake.original_dir).join('sorbet', 'dry-monads-sorbet')
|
14
16
|
end
|
15
17
|
|
16
18
|
def copy_bundled_rbi(filename)
|
17
|
-
puts "Copy bundled file #{filename}"
|
18
19
|
bundled_rbi_file_path = File.join(DRY_MONADS_SORBET_RAKE_DIR, '..', '..', 'bundled_rbi', filename)
|
19
20
|
copy_to_path = dry_monads_sorbet_rbi_path.join(filename)
|
20
21
|
FileUtils.mkdir_p(File.dirname(copy_to_path))
|
21
22
|
FileUtils.cp(bundled_rbi_file_path, copy_to_path)
|
23
|
+
puts "Copied bundled rbi file: #{filename}"
|
22
24
|
end
|
23
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-monads-sorbet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Worth
|
@@ -140,7 +140,11 @@ homepage: https://github.com/tricycle/dry-monads-sorbet
|
|
140
140
|
licenses:
|
141
141
|
- MIT
|
142
142
|
metadata: {}
|
143
|
-
post_install_message:
|
143
|
+
post_install_message: |
|
144
|
+
dry-monads-sorbet has been installed/updated.
|
145
|
+
|
146
|
+
This gem ships with a bundled rbi file that must be copied into your project.
|
147
|
+
You can use the included "dry_monads_sorbet:update_rbi" to do this.
|
144
148
|
rdoc_options: []
|
145
149
|
require_paths:
|
146
150
|
- lib
|
@@ -151,9 +155,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
155
|
version: '0'
|
152
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
157
|
requirements:
|
154
|
-
- - "
|
158
|
+
- - ">="
|
155
159
|
- !ruby/object:Gem::Version
|
156
|
-
version:
|
160
|
+
version: '0'
|
157
161
|
requirements: []
|
158
162
|
rubygems_version: 3.1.2
|
159
163
|
signing_key:
|