typ-formatter 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/typ/formatter.rb +59 -25
  3. metadata +35 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e4e33337a51f5d9c3e197e29cfcf3e5e51bbcbb341c923e5c0efc6a711e240c
4
- data.tar.gz: 22be26a0cfdc410f9b828f26ce691376e6bdba52e3b5fa148013332435fd0fd2
3
+ metadata.gz: 184d40fcdfb55dc0bf05cfafdde28da8c87fb5d45c60c4e46066ca48a4715cb5
4
+ data.tar.gz: 3a3d99f9e72ebeabfd455d4c7e306b078e316022beb9039f2ab550dd75f829d4
5
5
  SHA512:
6
- metadata.gz: 07062bb2dcd94f09916a69fa05eaa30bcc3e97114d8d956c10a8291b02d95ca9e2631be0fe1b1b0aff633933158c3316e489806bd9c45a18cae87408b1a29e18
7
- data.tar.gz: 42caa83d32d8a78692995ec255a2fd42ab55984e759e1d66f3aad29e0e548b69b920239c3e10e3b3f723a7f50afdcb041993881ae99a0a189ab18100aa9a3be9
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,30 +81,6 @@ module Typ
23
81
  end.join "\n"
24
82
  end
25
83
 
26
- def format_gate gate
27
- case gate
28
- when Typ
29
- self.class.new gate
30
- when Is::Array
31
- format_is_array gate
32
- when IsA
33
- format_is_a gate
34
- end
35
- end
36
-
37
- def format_is_array gate
38
- string = "is #{gate.to_a}"
39
- gate.ok? ? Rainbow(string).green : Rainbow(string).red
40
- end
41
-
42
- def format_is_a gate
43
- is_a = "is_a #{gate.class.type}"
44
-
45
- if gate.ok?
46
- Rainbow(is_a).green
47
- else
48
- Rainbow(is_a).red + "\n" + "got #{gate.it.class}".indent(2)
49
- end
50
- end
84
+ include FormatGate
51
85
  end
52
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.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - Anatoly Chernow
7
+ - Anatoly Chernov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-30 00:00:00.000000000 Z
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
- rubyforge_project:
67
- rubygems_version: 2.7.6
95
+ rubygems_version: 3.4.15
68
96
  signing_key:
69
97
  specification_version: 4
70
- summary: A formatter to create nice-looking strings from Typs.
98
+ summary: To format validations made with typs.
71
99
  test_files: []