Class: Spoom::Coverage::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/spoom/coverage/snapshot.rb

Constant Summary collapse

STRICTNESSES =

The strictness name as found in the Sorbet metrics file

["ignore", "false", "true", "strict", "strong", "stdlib"].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timestamp: Time.new.getutc.to_i, version_static: nil, version_runtime: nil, duration: 0, commit_sha: nil, commit_timestamp: nil, files: 0, rbi_files: 0, modules: 0, classes: 0, singleton_classes: 0, methods_without_sig: 0, methods_with_sig: 0, calls_untyped: 0, calls_typed: 0, sigils: Hash.new(0), methods_with_sig_excluding_rbis: 0, methods_without_sig_excluding_rbis: 0, sigils_excluding_rbis: Hash.new(0)) ⇒ Snapshot

: ( | ?timestamp: Integer, | ?version_static: String?, | ?version_runtime: String?, | ?duration: Integer, | ?commit_sha: String?, | ?commit_timestamp: Integer?, | ?files: Integer, | ?rbi_files: Integer, | ?modules: Integer, | ?classes: Integer, | ?singleton_classes: Integer, | ?methods_without_sig: Integer, | ?methods_with_sig: Integer, | ?calls_untyped: Integer, | ?calls_typed: Integer, | ?sigils: Hash[String, Integer], | ?methods_with_sig_excluding_rbis: Integer, | ?methods_without_sig_excluding_rbis: Integer, | ?sigils_excluding_rbis: Hash[String, Integer], | ) -> void



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/spoom/coverage/snapshot.rb', line 85

def initialize(
  timestamp: Time.new.getutc.to_i,
  version_static: nil,
  version_runtime: nil,
  duration: 0,
  commit_sha: nil,
  commit_timestamp: nil,
  files: 0,
  rbi_files: 0,
  modules: 0,
  classes: 0,
  singleton_classes: 0,
  methods_without_sig: 0,
  methods_with_sig: 0,
  calls_untyped: 0,
  calls_typed: 0,
  sigils: Hash.new(0),
  methods_with_sig_excluding_rbis: 0,
  methods_without_sig_excluding_rbis: 0,
  sigils_excluding_rbis: Hash.new(0)
)
  @timestamp = timestamp
  @version_static = version_static
  @version_runtime = version_runtime
  @duration = duration
  @commit_sha = commit_sha
  @commit_timestamp = commit_timestamp
  @files = files
  @rbi_files = rbi_files
  @modules = modules
  @classes = classes
  @singleton_classes = singleton_classes
  @methods_without_sig = methods_without_sig
  @methods_with_sig = methods_with_sig
  @calls_untyped = calls_untyped
  @calls_typed = calls_typed
  @sigils = sigils
  @methods_with_sig_excluding_rbis = methods_with_sig_excluding_rbis
  @methods_without_sig_excluding_rbis = methods_without_sig_excluding_rbis
  @sigils_excluding_rbis = sigils_excluding_rbis
end

Instance Attribute Details

#calls_typed ⇒ Object

: Integer



50
51
52
# File 'lib/spoom/coverage/snapshot.rb', line 50

def calls_typed
  @calls_typed
end

#calls_untyped ⇒ Object

: Integer



47
48
49
# File 'lib/spoom/coverage/snapshot.rb', line 47

def calls_untyped
  @calls_untyped
end

#classes ⇒ Object

: Integer



35
36
37
# File 'lib/spoom/coverage/snapshot.rb', line 35

def classes
  @classes
end

#commit_sha ⇒ Object

: String?



20
21
22
# File 'lib/spoom/coverage/snapshot.rb', line 20

def commit_sha
  @commit_sha
end

#commit_timestamp ⇒ Object

: Integer?



23
24
25
# File 'lib/spoom/coverage/snapshot.rb', line 23

def commit_timestamp
  @commit_timestamp
end

#duration ⇒ Object

: Integer



17
18
19
# File 'lib/spoom/coverage/snapshot.rb', line 17

def duration
  @duration
end

#files ⇒ Object

: Integer



26
27
28
# File 'lib/spoom/coverage/snapshot.rb', line 26

def files
  @files
end

#methods_with_sig ⇒ Object

: Integer



44
45
46
# File 'lib/spoom/coverage/snapshot.rb', line 44

def methods_with_sig
  @methods_with_sig
end

#methods_with_sig_excluding_rbis ⇒ Object

: Integer



56
57
58
# File 'lib/spoom/coverage/snapshot.rb', line 56

def methods_with_sig_excluding_rbis
  @methods_with_sig_excluding_rbis
end

#methods_without_sig ⇒ Object

: Integer



41
42
43
# File 'lib/spoom/coverage/snapshot.rb', line 41

def methods_without_sig
  @methods_without_sig
end

#methods_without_sig_excluding_rbis ⇒ Object

: Integer



59
60
61
# File 'lib/spoom/coverage/snapshot.rb', line 59

def methods_without_sig_excluding_rbis
  @methods_without_sig_excluding_rbis
end

#modules ⇒ Object

: Integer



32
33
34
# File 'lib/spoom/coverage/snapshot.rb', line 32

def modules
  @modules
end

#rbi_files ⇒ Object

: Integer



29
30
31
# File 'lib/spoom/coverage/snapshot.rb', line 29

def rbi_files
  @rbi_files
end

#sigils ⇒ Object

: Hash[String, Integer]



53
54
55
# File 'lib/spoom/coverage/snapshot.rb', line 53

def sigils
  @sigils
end

#sigils_excluding_rbis ⇒ Object

: Hash[String, Integer]



62
63
64
# File 'lib/spoom/coverage/snapshot.rb', line 62

def sigils_excluding_rbis
  @sigils_excluding_rbis
end

#singleton_classes ⇒ Object

: Integer



38
39
40
# File 'lib/spoom/coverage/snapshot.rb', line 38

def singleton_classes
  @singleton_classes
end

#timestamp ⇒ Object

: Integer



8
9
10
# File 'lib/spoom/coverage/snapshot.rb', line 8

def timestamp
  @timestamp
end

#version_runtime ⇒ Object

: String?



14
15
16
# File 'lib/spoom/coverage/snapshot.rb', line 14

def version_runtime
  @version_runtime
end

#version_static ⇒ Object

: String?



11
12
13
# File 'lib/spoom/coverage/snapshot.rb', line 11

def version_static
  @version_static
end

Class Method Details

.from_json(json) ⇒ Object

: (String json) -> Snapshot



169
170
171
# File 'lib/spoom/coverage/snapshot.rb', line 169

def from_json(json)
  from_obj(JSON.parse(json))
end

.from_obj(obj) ⇒ Object

: (Hash[String, untyped] obj) -> Snapshot



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/spoom/coverage/snapshot.rb', line 174

def from_obj(obj)
  snapshot = Snapshot.new
  snapshot.timestamp = obj.fetch("timestamp", 0)
  snapshot.version_static = obj.fetch("version_static", nil)
  snapshot.version_runtime = obj.fetch("version_runtime", nil)
  snapshot.duration = obj.fetch("duration", 0)
  snapshot.commit_sha = obj.fetch("commit_sha", nil)
  snapshot.commit_timestamp = obj.fetch("commit_timestamp", nil)
  snapshot.files = obj.fetch("files", 0)
  snapshot.rbi_files = obj.fetch("rbi_files", 0)
  snapshot.modules = obj.fetch("modules", 0)
  snapshot.classes = obj.fetch("classes", 0)
  snapshot.singleton_classes = obj.fetch("singleton_classes", 0)
  snapshot.methods_with_sig = obj.fetch("methods_with_sig", 0)
  snapshot.methods_without_sig = obj.fetch("methods_without_sig", 0)
  snapshot.calls_typed = obj.fetch("calls_typed", 0)
  snapshot.calls_untyped = obj.fetch("calls_untyped", 0)
  snapshot.methods_with_sig_excluding_rbis = obj.fetch("methods_with_sig_excluding_rbis", 0)
  snapshot.methods_without_sig_excluding_rbis = obj.fetch("methods_without_sig_excluding_rbis", 0)

  sigils = obj.fetch("sigils", {})
  if sigils
    Snapshot::STRICTNESSES.each do |strictness|
      next unless sigils.key?(strictness)

      snapshot.sigils[strictness] = sigils[strictness]
    end
  end

  sigils_excluding_rbis = obj.fetch("sigils_excluding_rbis", {})
  if sigils_excluding_rbis
    Snapshot::STRICTNESSES.each do |strictness|
      next unless sigils_excluding_rbis.key?(strictness)

      snapshot.sigils_excluding_rbis[strictness] = sigils_excluding_rbis[strictness]
    end
  end

  snapshot
end

Instance Method Details

: (?out: (IO | StringIO), ?colors: bool, ?indent_level: Integer) -> void



131
132
133
134
# File 'lib/spoom/coverage/snapshot.rb', line 131

def print(out: $stdout, colors: true, indent_level: 0)
  printer = SnapshotPrinter.new(out: out, colors: colors, indent_level: indent_level)
  printer.print_snapshot(self)
end

#to_h ⇒ Object

: -> Hash[String, untyped]



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/spoom/coverage/snapshot.rb', line 143

def to_h
  {
    "timestamp" => timestamp,
    "version_static" => version_static,
    "version_runtime" => version_runtime,
    "duration" => duration,
    "commit_sha" => commit_sha,
    "commit_timestamp" => commit_timestamp,
    "files" => files,
    "rbi_files" => rbi_files,
    "modules" => modules,
    "classes" => classes,
    "singleton_classes" => singleton_classes,
    "methods_with_sig" => methods_with_sig,
    "methods_without_sig" => methods_without_sig,
    "calls_typed" => calls_typed,
    "calls_untyped" => calls_untyped,
    "sigils" => sigils,
    "methods_with_sig_excluding_rbis" => methods_with_sig_excluding_rbis,
    "methods_without_sig_excluding_rbis" => methods_without_sig_excluding_rbis,
    "sigils_excluding_rbis" => sigils_excluding_rbis,
  }
end

#to_json(*arg) ⇒ Object

: (*untyped arg) -> String



137
138
139
140
# File 'lib/spoom/coverage/snapshot.rb', line 137

def to_json(*arg)
  to_h #: untyped
    .to_json(*arg)
end