typ 0.0.0
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 +7 -0
- data/lib/typ.rb +64 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8229c885608c560adc085e62bddcd8f3f1aaac35432619042a36527fcf42d393
|
4
|
+
data.tar.gz: e451a0dbacb13fb98fcdb9067bd3d8eca3fc38daf0dc56048a9ef8c35ca40ad0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 53f853a2fa6c08377c77e422bdbcf2087486a02056f9118723c537457c254ad7f7c3b1335f89686391ea36f50dc91b7f0064eee19274df86e050dc60a2e01916
|
7
|
+
data.tar.gz: a1f3e66a15dcd688112799a2aeffb9ccf75130ee32d0f61e6140d6f022a88ffd33ceae9653e3fd374df06a38db8a87f763881aeafc86fff1a39212158630f022
|
data/lib/typ.rb
ADDED
@@ -0,0 +1,64 @@
|
|
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
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize object
|
20
|
+
@object = object
|
21
|
+
@gates = self.class.gates.map { |gate| gate.new object }
|
22
|
+
@fails = gates.reject &:ok?
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :object, :gates, :fails
|
26
|
+
|
27
|
+
def ok?
|
28
|
+
fails.empty?
|
29
|
+
end
|
30
|
+
|
31
|
+
extend Singleton
|
32
|
+
|
33
|
+
class Gate
|
34
|
+
def ok?
|
35
|
+
@ok
|
36
|
+
end
|
37
|
+
|
38
|
+
class FromArray < Gate
|
39
|
+
class << self
|
40
|
+
attr_accessor :check
|
41
|
+
|
42
|
+
def [] array
|
43
|
+
check = if array[0].is_a?(Symbol)
|
44
|
+
method, *arguments = array
|
45
|
+
-> receiver { receiver.send method, *arguments }
|
46
|
+
elsif array[1].is_a?(Symbol)
|
47
|
+
receiver, method = array
|
48
|
+
-> argument { receiver.send method, argument }
|
49
|
+
else
|
50
|
+
fail "not sure how to handle #{array} yet"
|
51
|
+
end
|
52
|
+
|
53
|
+
gate = Class.new self
|
54
|
+
gate.check = check
|
55
|
+
gate
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def initialize object
|
60
|
+
@ok = self.class.check[object]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: typ
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anatoly Chernow
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/typ.rb
|
20
|
+
homepage:
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubyforge_project:
|
39
|
+
rubygems_version: 2.7.6
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: A tool for defining and enforcing types of Ruby objects.
|
43
|
+
test_files: []
|