rtype-java 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -48
- data/benchmark/benchmark.rb +9 -1
- data/ext/rtype/rtype_java.jar +0 -0
- data/spec/rtype_spec.rb +6 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26d9b5f52a0751920c528ad09892902417a87c6a
|
4
|
+
data.tar.gz: 17914c634ee6098bad49631b880639f198177395
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31b92c9b62a23d35acb9b2552c7c52dc5e94a3760bc513cc63d7439757e5e0d2a690c312ad3edaf0046ce48f4077c9a0d56000867afbb5434cd0e2d0a610864f
|
7
|
+
data.tar.gz: a7fd347eeb62797636bd729115b2c9a0df323a6a7d7e3285353e89ea6805761d191cdcfbb46669645974e61a062a9ff3324cc4108e3142f6d80e048948855f1c
|
data/README.md
CHANGED
@@ -29,6 +29,7 @@ Test::invert(state: 0)
|
|
29
29
|
|
30
30
|
## Requirements
|
31
31
|
- Ruby >= 2.1
|
32
|
+
- If you need to use old ruby, see [rtype-legacy](https://github.com/sputnikgugja/rtype-legacy) for ruby 1.9+
|
32
33
|
- MRI
|
33
34
|
- If C native extension is used. otherwise it is not required
|
34
35
|
- JRuby (JRuby 9000+)
|
@@ -40,6 +41,7 @@ Test::invert(state: 0)
|
|
40
41
|
- [Type checking for hash elements](#hash)
|
41
42
|
- [Duck Typing](#duck-typing)
|
42
43
|
- [Typed Array](#typed-array)
|
44
|
+
- [Numeric check](#special-behaviors). e.g. `Int >= 0`
|
43
45
|
- Custom type behavior
|
44
46
|
- ...
|
45
47
|
|
@@ -79,22 +81,21 @@ then, Rtype uses it. (**Do not** `require 'rtype-java'`)
|
|
79
81
|
## Usage
|
80
82
|
|
81
83
|
### Supported Type Behaviors
|
82
|
-
- `Module`
|
83
|
-
- Value must be of this module (`is_a?`)
|
84
|
+
- `Module` : Value must be of this module (`is_a?`)
|
84
85
|
- `Any` : Alias for `BasicObject` (means Any Object)
|
85
86
|
- `Boolean` : `true` or `false`
|
86
|
-
- `Symbol`
|
87
|
-
|
88
|
-
- `
|
89
|
-
|
90
|
-
- `
|
91
|
-
|
92
|
-
- `
|
93
|
-
|
87
|
+
- `Symbol` : Value must respond to a method with this name
|
88
|
+
- `Regexp` : Value must match this regexp pattern
|
89
|
+
- `Range` : Value must be included in this range
|
90
|
+
- `Array` : Value can be any type in this array
|
91
|
+
- `Proc` : Value must return a truthy value for this proc
|
92
|
+
- `true` : Value must be truthy
|
93
|
+
- `false` : Value must be falsy
|
94
|
+
- `nil` : Value must be nil
|
94
95
|
- `Hash`
|
95
96
|
- Value must be a hash
|
96
97
|
- Each of elements must be valid
|
97
|
-
-
|
98
|
+
- Keys of the value must be equal to keys of this hash
|
98
99
|
- **String** key is **different** from **symbol** key
|
99
100
|
- vs. Keyword arguments (e.g.)
|
100
101
|
- `[{}]` is **not** hash argument. it is keyword argument, because its position is last
|
@@ -103,44 +104,9 @@ then, Rtype uses it. (**Do not** `require 'rtype-java'`)
|
|
103
104
|
- `{}` is keyword argument. non-keyword arguments must be in array.
|
104
105
|
- Of course, nested hash works
|
105
106
|
- Example: [Hash](#hash)
|
106
|
-
- `Proc`
|
107
|
-
- Value must return a truthy value for this proc
|
108
|
-
- `true`
|
109
|
-
- Value must be truthy
|
110
|
-
- `false`
|
111
|
-
- Value must be falsy
|
112
|
-
- `nil`
|
113
|
-
- Value must be nil
|
114
107
|
|
115
|
-
- Special Behaviors
|
116
|
-
- `TypedArray`
|
117
|
-
- `Array::of(type)` (recommended)
|
118
|
-
- or `Rtype::Behavior::TypedArray[type]`
|
119
|
-
- Example: [TypedArray](#typed-array)
|
120
|
-
|
121
|
-
- `Num, Int, Flo` : Numeric check
|
122
|
-
- `Num/Int/Flo >/>=/</<=/== x`
|
123
|
-
- e.g. `Num >= 2` means value must be a `Numeric` and >= 2
|
124
|
-
- e.g. `Int >= 2` means value must be a `Integer` and >= 2
|
125
|
-
- e.g. `Flo >= 2` means value must be a `Float` and >= 2
|
126
|
-
|
127
|
-
- `And` : Ensures value is valid for all given types
|
128
|
-
- `Rtype::and(*types)`, `Rtype::Behavior::And[*types]`
|
129
|
-
- or `Array#comb`, `Object#and(*others)`
|
130
|
-
|
131
|
-
- `Xor` : Ensures value is valid for only one of given types
|
132
|
-
- `Rtype::xor(*types)`, `Rtype::Behavior::Xor[*types]`
|
133
|
-
- or `Object#xor(*others)`
|
134
|
-
|
135
|
-
- `Not` : Ensures value is not valid for all given types
|
136
|
-
- `Rtype::not(*types)`, `Rtype::Behavior::Not[*types]`
|
137
|
-
- or `Object#not`
|
138
|
-
|
139
|
-
- `Nilable` : Value can be nil
|
140
|
-
- `Rtype::nilable(type)`, `Rtype::Behavior::Nilable[type]`
|
141
|
-
- or `Object#nilable`, `Object#or_nil`
|
142
|
-
|
143
|
-
- You can create custom behavior by extending `Rtype::Behavior::Base`
|
108
|
+
- [Special Behaviors](#special-behaviors)
|
109
|
+
- `TypedArray`, `Num, Int, Flo`, `And`, `Xor`, `Not`, `Nilable`
|
144
110
|
|
145
111
|
### Examples
|
146
112
|
|
@@ -424,6 +390,36 @@ Example.new.method(:test).return_type
|
|
424
390
|
# => Any
|
425
391
|
```
|
426
392
|
|
393
|
+
#### Special Behaviors
|
394
|
+
- `TypedArray` : Ensures value is an array with the type (type signature)
|
395
|
+
- `Array::of(type)` (recommended)
|
396
|
+
- or `Rtype::Behavior::TypedArray[type]`
|
397
|
+
- Example: [TypedArray](#typed-array)
|
398
|
+
|
399
|
+
- `Num, Int, Flo` : Numeric check
|
400
|
+
- `Num/Int/Flo >/>=/</<=/== x`
|
401
|
+
- e.g. `Num >= 2` means value must be a `Numeric` and >= 2
|
402
|
+
- e.g. `Int >= 2` means value must be a `Integer` and >= 2
|
403
|
+
- e.g. `Flo >= 2` means value must be a `Float` and >= 2
|
404
|
+
|
405
|
+
- `And` : Ensures value is valid for all given types
|
406
|
+
- `Rtype::and(*types)`, `Rtype::Behavior::And[*types]`
|
407
|
+
- or `Array#comb`, `Object#and(*others)`
|
408
|
+
|
409
|
+
- `Xor` : Ensures value is valid for only one of given types
|
410
|
+
- `Rtype::xor(*types)`, `Rtype::Behavior::Xor[*types]`
|
411
|
+
- or `Object#xor(*others)`
|
412
|
+
|
413
|
+
- `Not` : Ensures value is not valid for all given types
|
414
|
+
- `Rtype::not(*types)`, `Rtype::Behavior::Not[*types]`
|
415
|
+
- or `Object#not`
|
416
|
+
|
417
|
+
- `Nilable` : Value can be nil
|
418
|
+
- `Rtype::nilable(type)`, `Rtype::Behavior::Nilable[type]`
|
419
|
+
- or `Object#nilable`, `Object#or_nil`
|
420
|
+
|
421
|
+
- You can create custom behaviors by extending `Rtype::Behavior::Base`
|
422
|
+
|
427
423
|
## Documentation
|
428
424
|
[RubyDoc.info](http://www.rubydoc.info/gems/rtype)
|
429
425
|
|
data/benchmark/benchmark.rb
CHANGED
@@ -19,6 +19,14 @@ puts "Sig version: #{Sig::VERSION}"
|
|
19
19
|
puts "Contracts version: #{Contracts::VERSION}"
|
20
20
|
puts "Typecheck version: #{Typecheck::VERSION}"
|
21
21
|
|
22
|
+
if !Rtype::NATIVE_EXT_VERSION.nil?
|
23
|
+
puts "Rtype with native extension"
|
24
|
+
elsif !Rtype::JAVA_EXT_VERSION.nil?
|
25
|
+
puts "Rtype with java extension"
|
26
|
+
else
|
27
|
+
puts "Rtype without native extension"
|
28
|
+
end
|
29
|
+
|
22
30
|
class PureTest
|
23
31
|
def sum(x, y)
|
24
32
|
x + y
|
@@ -189,4 +197,4 @@ Benchmark.ips do |x|
|
|
189
197
|
end
|
190
198
|
|
191
199
|
x.compare!
|
192
|
-
end
|
200
|
+
end
|
data/ext/rtype/rtype_java.jar
CHANGED
Binary file
|
data/spec/rtype_spec.rb
CHANGED
@@ -274,12 +274,12 @@ describe Rtype do
|
|
274
274
|
describe 'Hash' do
|
275
275
|
it "is right" do
|
276
276
|
klass.send :rtype, :return_arg, [{k: Integer}, {}] => Any
|
277
|
-
instance.return_arg({k: 123}
|
277
|
+
instance.return_arg({k: 123})
|
278
278
|
end
|
279
279
|
it "is wrong args" do
|
280
280
|
klass.send :rtype, :return_arg, [{k: Integer}, {}] => Any
|
281
281
|
expect {
|
282
|
-
instance.return_arg({k: "str"}
|
282
|
+
instance.return_arg({k: "str"})
|
283
283
|
}.to raise_error Rtype::ArgumentTypeError
|
284
284
|
end
|
285
285
|
it "is wrong result" do
|
@@ -556,15 +556,15 @@ describe Rtype do
|
|
556
556
|
|
557
557
|
it 'two hash' do
|
558
558
|
klass.send :rtype, :two_args, [{k: Integer}, {k: Integer}, {}] => Any
|
559
|
-
instance.two_args({k: 123}, {k: 456}
|
559
|
+
instance.two_args({k: 123}, {k: 456})
|
560
560
|
expect {
|
561
|
-
instance.two_args({k: 123}, {}
|
561
|
+
instance.two_args({k: 123}, {})
|
562
562
|
}.to raise_error Rtype::ArgumentTypeError
|
563
563
|
expect {
|
564
|
-
instance.two_args({k: 123}, 456
|
564
|
+
instance.two_args({k: 123}, 456)
|
565
565
|
}.to raise_error Rtype::ArgumentTypeError
|
566
566
|
expect {
|
567
|
-
instance.two_args({k: 123}, {k: "str"}
|
567
|
+
instance.two_args({k: 123}, {k: "str"})
|
568
568
|
}.to raise_error Rtype::ArgumentTypeError
|
569
569
|
end
|
570
570
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rtype-java
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sputnik Gugja
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rtype
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.6.
|
19
|
+
version: 0.6.5
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.6.
|
26
|
+
version: 0.6.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|