typ-formatter 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 +4 -4
- data/lib/typ/formatter.rb +59 -13
- metadata +35 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 184d40fcdfb55dc0bf05cfafdde28da8c87fb5d45c60c4e46066ca48a4715cb5
|
4
|
+
data.tar.gz: 3a3d99f9e72ebeabfd455d4c7e306b078e316022beb9039f2ab550dd75f829d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 323e9f6524bf55e6ba67eb4df399acf42d623d4599ffe861cce11d3f85a6d6386e378916513a7d1fc136977beecf1d63cf53c94733e703dc695baf59b5582613
|
7
|
+
data.tar.gz: 2571250e8ac0879d1b889373757e1712d75d236f3e1140a19beb7df62f2067f6f4b3a9e76492c147bd5bf92b600201438cad79e2710e2e248a2d929829bffcb0
|
data/lib/typ/formatter.rb
CHANGED
@@ -1,5 +1,63 @@
|
|
1
1
|
module Typ
|
2
2
|
class Formatter
|
3
|
+
module FormatGate
|
4
|
+
class Formatter
|
5
|
+
def initialize gate
|
6
|
+
@string = format gate
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
@string
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module ToPascalCase
|
15
|
+
refine Symbol do
|
16
|
+
def to_pascal_case
|
17
|
+
to_s.split('_').map(&:capitalize).join
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'ap'
|
23
|
+
|
24
|
+
using ToPascalCase
|
25
|
+
|
26
|
+
def format_gate gate
|
27
|
+
if gate.is_a? Typ
|
28
|
+
Typ::Formatter.new gate
|
29
|
+
else
|
30
|
+
FormatGate
|
31
|
+
.const_get(gate.dsl_method.to_pascal_case)
|
32
|
+
.new(gate).to_s
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Is < Formatter
|
37
|
+
def format gate
|
38
|
+
literal = gate.dsl_literal
|
39
|
+
|
40
|
+
case literal
|
41
|
+
when Array
|
42
|
+
string = "is #{literal}"
|
43
|
+
gate.ok? ? Rainbow(string).green : Rainbow(string).red
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class IsA < Formatter
|
49
|
+
def format gate
|
50
|
+
string = "is_a #{gate.dsl_literal}"
|
51
|
+
|
52
|
+
if gate.ok?
|
53
|
+
Rainbow(string).green
|
54
|
+
else
|
55
|
+
Rainbow(string).red + "\n" + "got #{gate.it.class}".indent(2) + "\n" + gate.it.ai.indent(4)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
3
61
|
require 'string/indent'
|
4
62
|
require 'rainbow'
|
5
63
|
|
@@ -23,18 +81,6 @@ module Typ
|
|
23
81
|
end.join "\n"
|
24
82
|
end
|
25
83
|
|
26
|
-
|
27
|
-
case gate
|
28
|
-
when Typ
|
29
|
-
self.class.new gate
|
30
|
-
when Is::Array
|
31
|
-
format_is_array gate
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def format_is_array gate
|
36
|
-
string = "is #{gate.to_a}"
|
37
|
-
gate.ok? ? Rainbow(string).green : Rainbow(string).red
|
38
|
-
end
|
84
|
+
include FormatGate
|
39
85
|
end
|
40
86
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typ-formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Anatoly
|
7
|
+
- Anatoly Chernov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: typ
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rainbow
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,8 +52,23 @@ dependencies:
|
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: awesome_print
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
description:
|
42
|
-
email:
|
70
|
+
email:
|
71
|
+
- chertoly@gmail.com
|
43
72
|
executables: []
|
44
73
|
extensions: []
|
45
74
|
extra_rdoc_files: []
|
@@ -63,9 +92,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
92
|
- !ruby/object:Gem::Version
|
64
93
|
version: '0'
|
65
94
|
requirements: []
|
66
|
-
|
67
|
-
rubygems_version: 2.7.6
|
95
|
+
rubygems_version: 3.4.15
|
68
96
|
signing_key:
|
69
97
|
specification_version: 4
|
70
|
-
summary:
|
98
|
+
summary: To format validations made with typs.
|
71
99
|
test_files: []
|