typ 0.1.0 → 0.1.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 +4 -4
- data/lib/typ.rb +64 -18
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 34eb85e4455df8349193687fe8d7d708e915721efcc504bbc9188a4a97a65bc5
|
|
4
|
+
data.tar.gz: 44d3854153877adff21b213dad11c0af9c36cb29b1923bf56311503dada4bad9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7eadd0c1c59c745e12b348fa797e688e020ad2828162d61c5bc06799491c8caf76512b8f174a99260f880d63145b695accb1f967d7464088254738ca6de83a61
|
|
7
|
+
data.tar.gz: 909d72a5e223bf2b859c099362ec359aa014642c735425e2e16a7a744964bce0b8e55fe60953d6739d75e943e067b8737497c711d99a61c3c6029385020ab2d7
|
data/lib/typ.rb
CHANGED
|
@@ -1,4 +1,35 @@
|
|
|
1
1
|
module Typ
|
|
2
|
+
module ArrayPredicate
|
|
3
|
+
refine Array do
|
|
4
|
+
def predicate?
|
|
5
|
+
(size == 2) &&
|
|
6
|
+
(self[0].is_a?(Symbol) || self[1].is_a?(Symbol))
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
module ArrayToTest
|
|
12
|
+
refine Object do
|
|
13
|
+
def bad_assertion it, name
|
|
14
|
+
fail Typ::Error::BadAssertion.new(it, name)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
refine Array do
|
|
19
|
+
def to_test
|
|
20
|
+
type = self
|
|
21
|
+
|
|
22
|
+
if type[0].is_a? Symbol
|
|
23
|
+
method, argument = type
|
|
24
|
+
-> it { it.send method, argument or bad_assertion(it, type) }
|
|
25
|
+
else
|
|
26
|
+
receiver, method = type
|
|
27
|
+
-> it { receiver.send method, it or bad_assertion(it, type) }
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
2
33
|
module Gate
|
|
3
34
|
module DSLReaders
|
|
4
35
|
def dsl_method
|
|
@@ -8,6 +39,18 @@ module Typ
|
|
|
8
39
|
def dsl_literal
|
|
9
40
|
self.class.dsl_literal
|
|
10
41
|
end
|
|
42
|
+
|
|
43
|
+
def dsl_key
|
|
44
|
+
self.class.dsl_key
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
module Name
|
|
49
|
+
attr_writer :name
|
|
50
|
+
|
|
51
|
+
def name
|
|
52
|
+
@name ||= self.class.to_s
|
|
53
|
+
end
|
|
11
54
|
end
|
|
12
55
|
|
|
13
56
|
module New
|
|
@@ -21,10 +64,11 @@ module Typ
|
|
|
21
64
|
end
|
|
22
65
|
|
|
23
66
|
module Singleton
|
|
24
|
-
attr_accessor :dsl_method, :dsl_literal
|
|
67
|
+
attr_accessor :dsl_method, :dsl_literal, :dsl_key
|
|
25
68
|
end
|
|
26
69
|
|
|
27
70
|
extend New
|
|
71
|
+
include Name
|
|
28
72
|
include DSLReaders
|
|
29
73
|
|
|
30
74
|
attr_reader :it, :error
|
|
@@ -47,6 +91,9 @@ module Typ
|
|
|
47
91
|
end
|
|
48
92
|
end
|
|
49
93
|
|
|
94
|
+
using ArrayPredicate
|
|
95
|
+
using ArrayToTest
|
|
96
|
+
|
|
50
97
|
def self.included mod
|
|
51
98
|
mod.extend DSL
|
|
52
99
|
mod.extend Singleton
|
|
@@ -82,18 +129,7 @@ module Typ
|
|
|
82
129
|
when Symbol
|
|
83
130
|
-> it { it.send type or bad_assertion(it, type) }
|
|
84
131
|
when Array
|
|
85
|
-
|
|
86
|
-
unless type[0].is_a?(Symbol) || type[1].is_a?(Symbol)
|
|
87
|
-
cannot_create_gate type
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
if type[0].is_a? Symbol
|
|
91
|
-
method, argument = type
|
|
92
|
-
-> it { it.send method, argument or bad_assertion(it, type) }
|
|
93
|
-
else
|
|
94
|
-
receiver, method = type
|
|
95
|
-
-> it { receiver.send method, it or bad_assertion(it, type) }
|
|
96
|
-
end
|
|
132
|
+
type.predicate? ? type.to_test : (cannot_create_gate type)
|
|
97
133
|
when Class
|
|
98
134
|
type if type.include? Typ
|
|
99
135
|
end
|
|
@@ -102,10 +138,6 @@ module Typ
|
|
|
102
138
|
def cannot_create_gate type
|
|
103
139
|
fail Typ::Error::CannotCreateGate.new(type)
|
|
104
140
|
end
|
|
105
|
-
|
|
106
|
-
def bad_assertion it, name
|
|
107
|
-
fail Typ::Error::BadAssertion.new(it, name)
|
|
108
|
-
end
|
|
109
141
|
end
|
|
110
142
|
|
|
111
143
|
def initialize method, literal, **kwargs
|
|
@@ -127,6 +159,7 @@ module Typ
|
|
|
127
159
|
augment_gate_with_check @test
|
|
128
160
|
gate.dsl_method = @method
|
|
129
161
|
gate.dsl_literal = @literal
|
|
162
|
+
gate.dsl_key = @kwargs[:name]
|
|
130
163
|
end
|
|
131
164
|
end
|
|
132
165
|
|
|
@@ -156,6 +189,19 @@ module Typ
|
|
|
156
189
|
@test = fetch_check >> type_check
|
|
157
190
|
enrich_gate
|
|
158
191
|
end
|
|
192
|
+
|
|
193
|
+
def test_for literal
|
|
194
|
+
case literal
|
|
195
|
+
when Symbol
|
|
196
|
+
literal.end_with?(??) ? super : (super [:eql?, literal])
|
|
197
|
+
when Array
|
|
198
|
+
literal.predicate? ? literal.to_test : (super [:eql?, literal])
|
|
199
|
+
when Class
|
|
200
|
+
literal.include?(Typ) ? super : (super [:eql?, literal])
|
|
201
|
+
else
|
|
202
|
+
super [:eql?, literal]
|
|
203
|
+
end
|
|
204
|
+
end
|
|
159
205
|
end
|
|
160
206
|
|
|
161
207
|
class Is < Gate
|
|
@@ -204,7 +250,7 @@ module Typ
|
|
|
204
250
|
|
|
205
251
|
class BadAssertion < self
|
|
206
252
|
def initialize it, method_name
|
|
207
|
-
message = "#{it} is #{method_name}"
|
|
253
|
+
message = "#{it.inspect} is #{method_name}"
|
|
208
254
|
super message
|
|
209
255
|
end
|
|
210
256
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: typ
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Anatoly Chernov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-08-
|
|
11
|
+
date: 2023-08-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description:
|
|
14
14
|
email:
|