typ 0.0.0 → 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/typ.rb +39 -31
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8229c885608c560adc085e62bddcd8f3f1aaac35432619042a36527fcf42d393
4
- data.tar.gz: e451a0dbacb13fb98fcdb9067bd3d8eca3fc38daf0dc56048a9ef8c35ca40ad0
3
+ metadata.gz: 1e38d74e0f2bb298612cbc9c76ce190d53537d1a204d00821f7d28a3afcc9ab6
4
+ data.tar.gz: 17d1212f324b8da8f7170d19e94f144f308d1dca53bf5b6697a68d742b79b52c
5
5
  SHA512:
6
- metadata.gz: 53f853a2fa6c08377c77e422bdbcf2087486a02056f9118723c537457c254ad7f7c3b1335f89686391ea36f50dc91b7f0064eee19274df86e050dc60a2e01916
7
- data.tar.gz: a1f3e66a15dcd688112799a2aeffb9ccf75130ee32d0f61e6140d6f022a88ffd33ceae9653e3fd374df06a38db8a87f763881aeafc86fff1a39212158630f022
6
+ metadata.gz: a96d036cc19728923e36e888663f6ba35ed18c1e168180f52344024be92c4d6f66a6480c8037fa7cfc644e166e10f6128f2973286eb88746681683b582489a11
7
+ data.tar.gz: fae6fb96a7f0ce79a5ceec290c597f1801e20647c438fcf5fbd3a06a252126cd17b5eae51008a3c4db0e1a76995a8f24699d2f525419b061194748e68b784052
data/lib/typ.rb CHANGED
@@ -1,44 +1,56 @@
1
- class Typ
2
- module Singleton
3
- module DSL
4
- def is type
5
- case type
6
- when Array
7
- gates << Gate::FromArray[type]
8
- end
9
- end
10
- end
11
-
12
- def gates
13
- @gates ||= []
14
- end
15
-
16
- include DSL
1
+ module Typ
2
+ def self.included mod
3
+ mod.extend DSL
17
4
  end
18
-
19
- def initialize object
20
- @object = object
21
- @gates = self.class.gates.map { |gate| gate.new object }
5
+
6
+ def initialize it
7
+ @it = it
8
+ @gates = self.class.gates.map { |gate| gate.new it }
22
9
  @fails = gates.reject &:ok?
23
10
  end
24
11
 
25
- attr_reader :object, :gates, :fails
12
+ attr_reader :it, :gates, :fails
26
13
 
27
14
  def ok?
28
15
  fails.empty?
29
16
  end
30
-
31
- extend Singleton
32
17
 
33
- class Gate
18
+ module DSL
19
+ def gates
20
+ @gates ||= []
21
+ end
22
+
23
+ def is type
24
+ case type
25
+ when Array
26
+ gates << Is::Array[type]
27
+ when Class
28
+ if type.include? Typ
29
+ gates << type
30
+ else
31
+ fail "don't know how to create a Gate from #{type}"
32
+ end
33
+ else
34
+ fail "don't know how to create a Gate from #{type}"
35
+ end
36
+ end
37
+ end
38
+
39
+ class Is
40
+ class << self
41
+ attr_accessor :check
42
+ end
43
+
44
+ def initialize object
45
+ @ok = self.class.check[object]
46
+ end
47
+
34
48
  def ok?
35
49
  @ok
36
50
  end
37
51
 
38
- class FromArray < Gate
52
+ class Array < self
39
53
  class << self
40
- attr_accessor :check
41
-
42
54
  def [] array
43
55
  check = if array[0].is_a?(Symbol)
44
56
  method, *arguments = array
@@ -55,10 +67,6 @@ class Typ
55
67
  gate
56
68
  end
57
69
  end
58
-
59
- def initialize object
60
- @ok = self.class.check[object]
61
- end
62
70
  end
63
71
  end
64
72
  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.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoly Chernow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-21 00:00:00.000000000 Z
11
+ date: 2018-04-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: