delivered 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +64 -0
- data/LICENSE.md +21 -0
- data/README.md +18 -0
- data/delivered.gemspec +21 -0
- data/lib/delivered/signature.rb +35 -0
- data/lib/delivered/version.rb +5 -0
- data/lib/delivered.rb +5 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3ab93c9434d5e06930f9fa814dfef95849cda9c6b76c611ed54b7c51d1e4856d
|
4
|
+
data.tar.gz: 868e6e469da0d2a07e752f7c35725414a99aa06ab898f13c8b177cf6c2d892f5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1d94413829107f3b7cd6c60d4a28fc9c98abc5649b5dca0987ba88499729798d090563c882630a3be7495d22c99c32011a219c8d819d11429f7b23afb15c1db6
|
7
|
+
data.tar.gz: ac6388a9494a423891d5d9260c42ca7c9e4c90f0d85be89f36e54732aaa0cac0c0797c1947f8d983aa544e2967000e8187925ca60087d3062fe05d10d5fbf072
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gemspec
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem 'rubocop'
|
9
|
+
end
|
10
|
+
|
11
|
+
group :test do
|
12
|
+
gem 'sus'
|
13
|
+
end
|
14
|
+
|
15
|
+
group :development, :test do
|
16
|
+
gem 'amazing_print'
|
17
|
+
gem 'debug', platforms: %i[mri mingw x64_mingw]
|
18
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
delivered (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
amazing_print (1.6.0)
|
10
|
+
ast (2.4.2)
|
11
|
+
debug (1.9.1)
|
12
|
+
irb (~> 1.10)
|
13
|
+
reline (>= 0.3.8)
|
14
|
+
io-console (0.7.2)
|
15
|
+
irb (1.12.0)
|
16
|
+
rdoc
|
17
|
+
reline (>= 0.4.2)
|
18
|
+
json (2.7.1)
|
19
|
+
language_server-protocol (3.17.0.3)
|
20
|
+
parallel (1.24.0)
|
21
|
+
parser (3.3.0.5)
|
22
|
+
ast (~> 2.4.1)
|
23
|
+
racc
|
24
|
+
psych (5.1.2)
|
25
|
+
stringio
|
26
|
+
racc (1.7.3)
|
27
|
+
rainbow (3.1.1)
|
28
|
+
rdoc (6.6.3.1)
|
29
|
+
psych (>= 4.0.0)
|
30
|
+
regexp_parser (2.9.0)
|
31
|
+
reline (0.5.0)
|
32
|
+
io-console (~> 0.5)
|
33
|
+
rexml (3.2.6)
|
34
|
+
rubocop (1.62.1)
|
35
|
+
json (~> 2.3)
|
36
|
+
language_server-protocol (>= 3.17.0)
|
37
|
+
parallel (~> 1.10)
|
38
|
+
parser (>= 3.3.0.2)
|
39
|
+
rainbow (>= 2.2.2, < 4.0)
|
40
|
+
regexp_parser (>= 1.8, < 3.0)
|
41
|
+
rexml (>= 3.2.5, < 4.0)
|
42
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
43
|
+
ruby-progressbar (~> 1.7)
|
44
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
45
|
+
rubocop-ast (1.31.2)
|
46
|
+
parser (>= 3.3.0.4)
|
47
|
+
ruby-progressbar (1.13.0)
|
48
|
+
stringio (3.1.0)
|
49
|
+
sus (0.24.6)
|
50
|
+
unicode-display_width (2.5.0)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
arm64-darwin-22
|
54
|
+
ruby
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
amazing_print
|
58
|
+
debug
|
59
|
+
delivered!
|
60
|
+
rubocop
|
61
|
+
sus
|
62
|
+
|
63
|
+
BUNDLED WITH
|
64
|
+
2.5.4
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) 2024 Joel Moss <joel@developwithstyle.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Delivered: Simple runtime type checking for Ruby method signatures
|
2
|
+
|
3
|
+
Delivered gives you the ability to define method signatures in Ruby, and have them checked at
|
4
|
+
runtime. This is useful for ensuring that your methods are being called with the correct arguments,
|
5
|
+
and for providing better error messages when they are not.
|
6
|
+
|
7
|
+
Simply define a method signature using the `sig` method directly before the method to be checked,
|
8
|
+
and Delivered will check that the method is being called with the correct arguments and types. it
|
9
|
+
can alos chreck the return value of the method.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
class User
|
13
|
+
sig String, age: Integer, returns: String
|
14
|
+
def create(name, age:)
|
15
|
+
"User #{name} created with age #{age}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
```
|
data/delivered.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# $:.unshift File.expand_path('lib', __dir__)
|
4
|
+
require_relative 'lib/delivered/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'delivered'
|
8
|
+
s.version = Delivered::VERSION
|
9
|
+
s.authors = ['Joel Moss']
|
10
|
+
s.email = ['joel@developwithstyle.com']
|
11
|
+
s.homepage = 'https://github.com/joelmoss/delivered'
|
12
|
+
s.licenses = ['MIT']
|
13
|
+
s.summary = 'Simple runtime type checking for Ruby method signatures'
|
14
|
+
s.required_ruby_version = '>= 3.2'
|
15
|
+
|
16
|
+
s.files = Dir.glob('{bin/*,lib/**/*,[A-Z]*}')
|
17
|
+
s.platform = Gem::Platform::RUBY
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
21
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Delivered
|
4
|
+
module Signature
|
5
|
+
NULL = Object.new
|
6
|
+
|
7
|
+
def sig(*sig_args, returns: NULL, **sig_kwargs)
|
8
|
+
meta = class << self; self; end
|
9
|
+
meta.send :define_method, :method_added do |name|
|
10
|
+
meta.send :remove_method, :method_added
|
11
|
+
|
12
|
+
alias_method :"__#{name}", name
|
13
|
+
define_method name do |*args, **kwargs, &block|
|
14
|
+
sig_args.each.with_index do |arg, i|
|
15
|
+
args[i] => ^arg
|
16
|
+
end
|
17
|
+
|
18
|
+
kwargs.each do |key, value|
|
19
|
+
value => ^(sig_kwargs[key])
|
20
|
+
end
|
21
|
+
|
22
|
+
result = if block
|
23
|
+
send(:"__#{name}", *args, **kwargs, &block)
|
24
|
+
else
|
25
|
+
send(:"__#{name}", *args, **kwargs)
|
26
|
+
end
|
27
|
+
|
28
|
+
result => ^returns if returns != NULL
|
29
|
+
|
30
|
+
result
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/delivered.rb
ADDED
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: delivered
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joel Moss
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- joel@developwithstyle.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- Gemfile
|
21
|
+
- Gemfile.lock
|
22
|
+
- LICENSE.md
|
23
|
+
- README.md
|
24
|
+
- delivered.gemspec
|
25
|
+
- lib/delivered.rb
|
26
|
+
- lib/delivered/signature.rb
|
27
|
+
- lib/delivered/version.rb
|
28
|
+
homepage: https://github.com/joelmoss/delivered
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
metadata:
|
32
|
+
rubygems_mfa_required: 'true'
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '3.2'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubygems_version: 3.5.7
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: Simple runtime type checking for Ruby method signatures
|
52
|
+
test_files: []
|