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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 015f97c2285dac2ec81370f391be68fe2f0e0e12
4
- data.tar.gz: 3769a9e66a2c4dd76426f1df7c101689d69d1983
3
+ metadata.gz: 267358ed190de5d88ffe6e114b467457eec61421
4
+ data.tar.gz: 851035b76cbfd2cece932f13815fe05d54d9f2fe
5
5
  SHA512:
6
- metadata.gz: 4f01f554ff61a8002c853b699b9ea393fac00585560143e396fdad79b6953220e893a9b21b298962ca5eac3158af7719ae0b73f2dbbacbe916a220dd099f4cc3
7
- data.tar.gz: b28b4edaca9aa181c37189d8abd1613d03857e67379c6b3d0595841f11fb4ba54f3cd788160b2a36dfc4c42669304cf470b9c0dc965852c7aae82fb9eb0bdecf
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.define do
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
- When the `Contract` module is included, the methods `contract` and
40
- `verify` become available.
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
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "contract"
3
- s.version = "0.0.1"
3
+ s.version = "0.1.0"
4
4
  s.summary = "Contract helper"
5
5
  s.description = "Contract helper"
6
6
  s.authors = ["Michel Martens"]
@@ -6,24 +6,17 @@ module Contract
6
6
 
7
7
  # Returns the value of the block
8
8
  # if all verifications pass
9
- def self.define(&block)
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 self.verify(value)
16
+ def verify(value)
17
17
  value || throw(:contract, false)
18
18
  end
19
19
 
20
- # Shorthand for Contract.define
21
- def contract(&block)
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
@@ -2,7 +2,7 @@ require_relative "../lib/contract"
2
2
 
3
3
  class Foo
4
4
  def foo(a, b)
5
- Contract.define do
5
+ Contract.contract do
6
6
  Contract.verify(Numeric === a)
7
7
  Contract.verify(Numeric === b)
8
8
 
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.1
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-08 00:00:00.000000000 Z
11
+ date: 2014-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest