contracts 0.17.1 → 0.17.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d5a8e7593b70e99ae8c0f56e6bf4484b884ecfbb740a418f27a78321ca856c9
|
4
|
+
data.tar.gz: c62fb8724ebfe3aea0dc2ff4ae8f9af119192d84d57244076ae83d60a5d26c03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea0815ee43b56200ab8465c112f5144989a0ac12c1a9e463ec7bc61ab14b1eeae5ef226ffed7961770b59d57fcfac3527445620cafaa55675337d289beedac4b
|
7
|
+
data.tar.gz: 1895e5c8786d024696e05be452c749f1f830e538b348d30fc9deb165f92a3f87697659b5fef784a65e4eda5f4306ed3c38a7d8622ef72fd76bd5cd38e41f3b1f
|
data/CHANGELOG.markdown
CHANGED
@@ -1,4 +1,18 @@
|
|
1
1
|
|
2
|
+
## [v0.17.1] - 2024-10-06
|
3
|
+
|
4
|
+
[v0.17.1]: https://github.com/egonSchiele/contracts.ruby/compare/v0.17...v0.17.1
|
5
|
+
|
6
|
+
- Bugfix: Fix keyword arguments contract when used with optional positional arguments - [PikachuEXE](https://github.com/PikachuEXE) [#305](https://github.com/egonSchiele/contracts.ruby/pull/305)
|
7
|
+
- Enhancement: Always load version.rb, suppress legacy deprecation warning - [Vlad Pisanov](https://github.com/vlad-pisanov) [#301](https://github.com/egonSchiele/contracts.ruby/pull/306)
|
8
|
+
- Enhancement: Update doc & spec about deprecated `Fixnum` to `Integer` - [PikachuEXE](https://github.com/PikachuEXE) [#301](https://github.com/egonSchiele/contracts.ruby/pull/301)
|
9
|
+
|
10
|
+
## [v0.17] - 2021-09-28
|
11
|
+
|
12
|
+
[v0.17]: https://github.com/egonSchiele/contracts.ruby/compare/v0.16.1...v0.17
|
13
|
+
|
14
|
+
- Update implementation & spec to be 3.0 compatible **Support for Ruby 2 has been discontinued** - [PikachuEXE](https://github.com/PikachuEXE) [#295](https://github.com/egonSchiele/contracts.ruby/pull/295)
|
15
|
+
|
2
16
|
## [v0.16.1] - 2021-04-17
|
3
17
|
|
4
18
|
[v0.16.1]: https://github.com/egonSchiele/contracts.ruby/compare/v0.16.0...v0.16.1
|
@@ -20,7 +34,7 @@
|
|
20
34
|
[v0.15.0]: https://github.com/egonSchiele/contracts.ruby/compare/v0.14.0...v0.15.0
|
21
35
|
|
22
36
|
- Bugfix: Func contract's return value isn't enforced with blocks - [Piotr Szmielew](https://github.com/esse) [#251](https://github.com/egonSchiele/contracts.ruby/pull/251)
|
23
|
-
-
|
37
|
+
- Bugfix: Fix contracts used in AR-models - [Gert Goet](https://github.com/eval) [#237](https://github.com/egonSchiele/contracts.ruby/pull/237)
|
24
38
|
|
25
39
|
## [v0.14.0] - 2016-04-26
|
26
40
|
|
@@ -0,0 +1,133 @@
|
|
1
|
+
Feature: Method Overloading
|
2
|
+
|
3
|
+
You can use contracts for method overloading! This is commonly called "pattern matching" in functional programming languages.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
Contract 1 => 1
|
7
|
+
def fact x
|
8
|
+
x
|
9
|
+
end
|
10
|
+
|
11
|
+
Contract C::Num => C::Num
|
12
|
+
def fact x
|
13
|
+
x * fact(x - 1)
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
Background:
|
18
|
+
Given a file named "method_overloading_with_positional_args_usage.rb" with:
|
19
|
+
"""ruby
|
20
|
+
require "contracts"
|
21
|
+
C = Contracts
|
22
|
+
|
23
|
+
class Example
|
24
|
+
include Contracts::Core
|
25
|
+
|
26
|
+
Contract 1 => 1
|
27
|
+
def fact(x)
|
28
|
+
x
|
29
|
+
end
|
30
|
+
|
31
|
+
Contract C::Num => C::Num
|
32
|
+
def fact(x)
|
33
|
+
x * fact(x - 1)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
"""
|
37
|
+
|
38
|
+
Given a file named "method_overloading_with_keyword_args_usage.rb" with:
|
39
|
+
"""ruby
|
40
|
+
require "contracts"
|
41
|
+
C = Contracts
|
42
|
+
|
43
|
+
class Example
|
44
|
+
include Contracts::Core
|
45
|
+
|
46
|
+
Contract C::KeywordArgs[age: Integer, size: Symbol] => String
|
47
|
+
def speak(age:, size:)
|
48
|
+
"age: #{age} size: #{size}"
|
49
|
+
end
|
50
|
+
|
51
|
+
Contract C::KeywordArgs[sound: String] => String
|
52
|
+
def speak(sound:)
|
53
|
+
"sound: #{sound}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
"""
|
57
|
+
|
58
|
+
Scenario: Positional Args Method 1
|
59
|
+
Given a file named "positional_args_method_1.rb" with:
|
60
|
+
"""ruby
|
61
|
+
require "./method_overloading_with_positional_args_usage"
|
62
|
+
puts Example.new.fact(1)
|
63
|
+
"""
|
64
|
+
When I run `ruby positional_args_method_1.rb`
|
65
|
+
Then the output should contain:
|
66
|
+
"""
|
67
|
+
1
|
68
|
+
"""
|
69
|
+
|
70
|
+
Scenario: Positional Args Method 2
|
71
|
+
Given a file named "positional_args_method_2.rb" with:
|
72
|
+
"""ruby
|
73
|
+
require "./method_overloading_with_positional_args_usage"
|
74
|
+
puts Example.new.fact(4)
|
75
|
+
"""
|
76
|
+
When I run `ruby positional_args_method_2.rb`
|
77
|
+
Then the output should contain:
|
78
|
+
"""
|
79
|
+
24
|
80
|
+
"""
|
81
|
+
|
82
|
+
Scenario: Keyword Args Method 1
|
83
|
+
Given a file named "keyword_args_method_1.rb" with:
|
84
|
+
"""ruby
|
85
|
+
require "./method_overloading_with_keyword_args_usage"
|
86
|
+
puts Example.new.speak(age: 5, size: :large)
|
87
|
+
"""
|
88
|
+
When I run `ruby keyword_args_method_1.rb`
|
89
|
+
Then the output should contain:
|
90
|
+
"""
|
91
|
+
age: 5 size: large
|
92
|
+
"""
|
93
|
+
|
94
|
+
Scenario: Keyword Args Method 2
|
95
|
+
Given a file named "keyword_args_method_2.rb" with:
|
96
|
+
"""ruby
|
97
|
+
require "./method_overloading_with_keyword_args_usage"
|
98
|
+
puts Example.new.speak(sound: "woof")
|
99
|
+
"""
|
100
|
+
When I run `ruby keyword_args_method_2.rb`
|
101
|
+
Then the output should contain:
|
102
|
+
"""
|
103
|
+
sound: woof
|
104
|
+
"""
|
105
|
+
|
106
|
+
Scenario: Incorrect Positional Args Method
|
107
|
+
Given a file named "incorrect_positional_args_method.rb" with:
|
108
|
+
"""ruby
|
109
|
+
require "contracts"
|
110
|
+
C = Contracts
|
111
|
+
|
112
|
+
class Example
|
113
|
+
include Contracts::Core
|
114
|
+
|
115
|
+
# Notice that this method's contract is wider than the one below
|
116
|
+
# This would cause this method to be called every time but never the one below
|
117
|
+
Contract C::Num => C::Num
|
118
|
+
def fact(x)
|
119
|
+
x * fact(x - 1)
|
120
|
+
end
|
121
|
+
|
122
|
+
Contract 1 => 1
|
123
|
+
def fact(x)
|
124
|
+
x
|
125
|
+
end
|
126
|
+
end
|
127
|
+
puts Example.new.fact(4)
|
128
|
+
"""
|
129
|
+
When I run `ruby incorrect_positional_args_method.rb`
|
130
|
+
Then the output should contain:
|
131
|
+
"""
|
132
|
+
stack level too deep (SystemStackError)
|
133
|
+
"""
|
@@ -174,8 +174,10 @@ https://github.com/egonSchiele/contracts.ruby/issues
|
|
174
174
|
|
175
175
|
def validate_pattern_matching!
|
176
176
|
new_args_contract = decorator.args_contracts
|
177
|
+
new_kargs_contract = decorator.kargs_contract
|
177
178
|
matched = decorated_methods.select do |contract|
|
178
|
-
contract.args_contracts == new_args_contract
|
179
|
+
contract.args_contracts == new_args_contract &&
|
180
|
+
contract.kargs_contract == new_kargs_contract
|
179
181
|
end
|
180
182
|
|
181
183
|
return if matched.empty?
|
data/lib/contracts/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contracts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.17.
|
4
|
+
version: 0.17.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aditya Bhargava
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This library provides contracts for Ruby. Contracts let you clearly express
|
14
14
|
how your code behaves, and free you from writing tons of boilerplate, defensive
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- cucumber.yml
|
41
41
|
- dependabot.yml
|
42
42
|
- features/README.md
|
43
|
+
- features/advanced/pattern_matching.feature
|
43
44
|
- features/basics/functype.feature
|
44
45
|
- features/basics/pretty-print.feature
|
45
46
|
- features/basics/simple_example.feature
|