Class: RSpec::FlakeClassifier::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/flake/classifier/signature.rb,
sig/rspec/flake/classifier.rbs

Constant Summary collapse

PLACEHOLDERS =
{
  object_address: "0xADDR",
  tmp_path: "<TMP>",
  line: ":LINE",
  seed: "SEED",
  timestamp: "<TIME>",
  cwd: "<PWD>"
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message:, backtrace: []) ⇒ Signature

Returns a new instance of Signature.

Parameters:

  • message: (String)
  • backtrace: (Array[String]) (defaults to: [])


26
27
28
29
30
31
# File 'lib/rspec/flake/classifier/signature.rb', line 26

def initialize(message:, backtrace: [])
  @message = message.to_s
  @backtrace = Array(backtrace).map(&:to_s)
  @normalized = normalize([@message, *@backtrace].join("\n"))
  @digest = Digest::SHA256.hexdigest(@normalized)
end

Instance Attribute Details

#backtraceArray[String] (readonly)

Returns the value of attribute backtrace.

Returns:

  • (Array[String])


17
18
19
# File 'lib/rspec/flake/classifier/signature.rb', line 17

def backtrace
  @backtrace
end

#digestString (readonly)

Returns the value of attribute digest.

Returns:

  • (String)


17
18
19
# File 'lib/rspec/flake/classifier/signature.rb', line 17

def digest
  @digest
end

#messageString (readonly)

Returns the value of attribute message.

Returns:

  • (String)


17
18
19
# File 'lib/rspec/flake/classifier/signature.rb', line 17

def message
  @message
end

#normalizedString (readonly)

Returns the value of attribute normalized.

Returns:

  • (String)


17
18
19
# File 'lib/rspec/flake/classifier/signature.rb', line 17

def normalized
  @normalized
end

Class Method Details

.from_exception(exception) ⇒ Signature

Parameters:

  • exception (Exception)

Returns:



19
20
21
22
23
24
# File 'lib/rspec/flake/classifier/signature.rb', line 19

def self.from_exception(exception)
  new(
    message: exception.message,
    backtrace: Array(exception.backtrace)
  )
end

Instance Method Details

#to_hHash[String, untyped]

Returns:

  • (Hash[String, untyped])


33
34
35
36
37
38
39
40
# File 'lib/rspec/flake/classifier/signature.rb', line 33

def to_h
  {
    "digest" => digest,
    "message" => message,
    "normalized" => normalized,
    "backtrace" => backtrace
  }
end