contract 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -4
- data/contract.gemspec +1 -1
- data/lib/contract.rb +4 -11
- data/test/contract_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 267358ed190de5d88ffe6e114b467457eec61421
|
4
|
+
data.tar.gz: 851035b76cbfd2cece932f13815fe05d54d9f2fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8a3aca5c6c1f9d791ec300139213529680b92d88c8c298e6f6ae56962dbb3a16327ee256fdc91161930d5603e9cc0f65b5b202665f957993633009645faf45c
|
7
|
+
data.tar.gz: 665bf07e4bb4432516d1b3a17361234c47e7d2618b5f110486725dcee3f5c0aa017c1dc23564b8bec2ab407c3651d895522fe056f7a39b11574fc6a2f4c9512f
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ The functions of a contract can be used directly from the
|
|
11
11
|
``` ruby
|
12
12
|
class Foo
|
13
13
|
def foo(a, b)
|
14
|
-
Contract.
|
14
|
+
Contract.contract do
|
15
15
|
Contract.verify(Numeric === a)
|
16
16
|
Contract.verify(Numeric === b)
|
17
17
|
|
@@ -19,8 +19,14 @@ class Foo
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
assert_equal 6, Foo.new.foo(2, 3)
|
24
|
+
assert_equal false, Foo.new.foo(2, "3")
|
22
25
|
```
|
23
26
|
|
27
|
+
When the `Contract` module is included, the methods `contract` and
|
28
|
+
`verify` become available.
|
29
|
+
|
24
30
|
``` ruby
|
25
31
|
class Bar
|
26
32
|
include Contract
|
@@ -34,10 +40,10 @@ class Bar
|
|
34
40
|
end
|
35
41
|
end
|
36
42
|
end
|
37
|
-
```
|
38
43
|
|
39
|
-
|
40
|
-
|
44
|
+
assert_equal 6, Bar.new.bar(2, 3)
|
45
|
+
assert_equal false, Bar.new.bar(2, "3")
|
46
|
+
```
|
41
47
|
|
42
48
|
## Installation
|
43
49
|
|
data/contract.gemspec
CHANGED
data/lib/contract.rb
CHANGED
@@ -6,24 +6,17 @@ module Contract
|
|
6
6
|
|
7
7
|
# Returns the value of the block
|
8
8
|
# if all verifications pass
|
9
|
-
def
|
9
|
+
def contract
|
10
10
|
catch(:contract) do
|
11
11
|
yield
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
# Fails unless value is true
|
16
|
-
def
|
16
|
+
def verify(value)
|
17
17
|
value || throw(:contract, false)
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
Contract.define(&block)
|
23
|
-
end
|
24
|
-
|
25
|
-
# Shorthand for Contract.verify
|
26
|
-
def verify(value)
|
27
|
-
Contract.verify(value)
|
28
|
-
end
|
20
|
+
module_function :contract
|
21
|
+
module_function :verify
|
29
22
|
end
|
data/test/contract_test.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contract
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cutest
|