typ-formatter 0.1.0 → 0.1.2

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 +52 -7
  3. metadata +16 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 184d40fcdfb55dc0bf05cfafdde28da8c87fb5d45c60c4e46066ca48a4715cb5
4
- data.tar.gz: 3a3d99f9e72ebeabfd455d4c7e306b078e316022beb9039f2ab550dd75f829d4
3
+ metadata.gz: 13b522d7882ac57e1b82d09342f3bf0a8422a61b274d74fd29737fbcf60d0a82
4
+ data.tar.gz: 7047a7cc861058201e488d232d3ec07ef397ab9f4b968d5e090ee61d66b4628b
5
5
  SHA512:
6
- metadata.gz: 323e9f6524bf55e6ba67eb4df399acf42d623d4599ffe861cce11d3f85a6d6386e378916513a7d1fc136977beecf1d63cf53c94733e703dc695baf59b5582613
7
- data.tar.gz: 2571250e8ac0879d1b889373757e1712d75d236f3e1140a19beb7df62f2067f6f4b3a9e76492c147bd5bf92b600201438cad79e2710e2e248a2d929829bffcb0
6
+ metadata.gz: fb7ea2ae8dc7c4c1de4c0481a0a740a3c982c31820617f7820abfc658271e0a882e9feae2f3caef6039cd9e9cfa8944fda4e7cc3dc9cfbb710b9536ae6301a58
7
+ data.tar.gz: a626757747049127ff9f2cb4dcc4e333dcf1b47681ab2bccd9d7f10fa11843a923619d56f11936c5595f10bc9a437961f6ef9df397750e235e44f00cf6973c0c
data/lib/typ/formatter.rb CHANGED
@@ -3,12 +3,45 @@ module Typ
3
3
  module FormatGate
4
4
  class Formatter
5
5
  def initialize gate
6
- @string = format gate
6
+ @gate = gate
7
+ @string = format
7
8
  end
8
9
 
10
+ attr_reader :gate
11
+
9
12
  def to_s
10
13
  @string
11
14
  end
15
+
16
+ def head
17
+ @head ||= if gate.dsl_key
18
+ "#{gate.dsl_method} #{gate.dsl_key.inspect} #{gate.dsl_literal.inspect}"
19
+ else
20
+ "#{gate.dsl_method} #{gate.dsl_literal}"
21
+ end
22
+ end
23
+
24
+ def actual
25
+ end
26
+
27
+ def format
28
+ if gate.ok?
29
+ Rainbow(head).green
30
+ else
31
+ error = gate.error
32
+ string = case error
33
+ when Typ::Error::BadAssertion
34
+ actual_type = "got #{actual.class}".indent 2
35
+ actual_value = actual.ai.indent 4
36
+
37
+ actual_type + "\n" + actual_value
38
+ else
39
+ (error.class.to_s.indent 2) + ":\n" + (error.to_s.indent 4)
40
+ end
41
+
42
+ Rainbow(head).red + "\n" + string
43
+ end
44
+ end
12
45
  end
13
46
 
14
47
  module ToPascalCase
@@ -29,12 +62,12 @@ module Typ
29
62
  else
30
63
  FormatGate
31
64
  .const_get(gate.dsl_method.to_pascal_case)
32
- .new(gate).to_s
65
+ .new(gate)
33
66
  end
34
67
  end
35
68
 
36
69
  class Is < Formatter
37
- def format gate
70
+ def format
38
71
  literal = gate.dsl_literal
39
72
 
40
73
  case literal
@@ -46,7 +79,7 @@ module Typ
46
79
  end
47
80
 
48
81
  class IsA < Formatter
49
- def format gate
82
+ def format
50
83
  string = "is_a #{gate.dsl_literal}"
51
84
 
52
85
  if gate.ok?
@@ -56,17 +89,29 @@ module Typ
56
89
  end
57
90
  end
58
91
  end
92
+
93
+ class Its < Formatter
94
+ def actual
95
+ gate.it.send gate.dsl_key
96
+ end
97
+ end
98
+
99
+ class Key < Formatter
100
+ def actual
101
+ gate.it[gate.dsl_key]
102
+ end
103
+ end
59
104
  end
60
105
 
61
106
  require 'string/indent'
62
107
  require 'rainbow'
63
108
 
64
109
  def initialize typ
65
- k = typ.class
110
+ n = typ.name
66
111
  @string = if typ.ok?
67
- Rainbow(k).green
112
+ Rainbow(n).green
68
113
  else
69
- Rainbow(k).red + "\n" + format_gates_of(typ).indent(2)
114
+ Rainbow(n).red + "\n" + format_gates_of(typ).indent(2)
70
115
  end
71
116
  end
72
117
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typ-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
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-01 00:00:00.000000000 Z
11
+ date: 2023-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typ
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.0
19
+ version: 0.1.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.0
26
+ version: 0.1.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rainbow
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 3.1.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 3.1.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: string-indent
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 0.0.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 0.0.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: awesome_print
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 1.9.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 1.9.2
69
69
  description:
70
70
  email:
71
71
  - chertoly@gmail.com