Class: Fingerprint::Sha1

Inherits:
Object
  • Object
show all
Defined in:
app/models/fingerprint/sha1.rb

Direct Known Subclasses

MD5

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(notice, api_key) ⇒ Sha1


12
13
14
15
# File 'app/models/fingerprint/sha1.rb', line 12

def initialize(notice, api_key)
  @notice = notice
  @api_key = api_key
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key


6
7
8
# File 'app/models/fingerprint/sha1.rb', line 6

def api_key
  @api_key
end

#noticeObject (readonly)

Returns the value of attribute notice


6
7
8
# File 'app/models/fingerprint/sha1.rb', line 6

def notice
  @notice
end

Class Method Details

.generate(notice, api_key) ⇒ Object


8
9
10
# File 'app/models/fingerprint/sha1.rb', line 8

def self.generate(notice, api_key)
  self.new(notice, api_key).to_s
end

Instance Method Details

#file_or_messageObject


32
33
34
# File 'app/models/fingerprint/sha1.rb', line 32

def file_or_message
  @file_or_message ||= unified_message + notice.backtrace.fingerprint
end

#fingerprint_sourceObject


21
22
23
24
25
26
27
28
29
30
# File 'app/models/fingerprint/sha1.rb', line 21

def fingerprint_source
  {
    :file_or_message => file_or_message,
    :error_class => notice.error_class,
    :component => notice.component || 'unknown',
    :action => notice.action,
    :environment => notice.environment_name || 'development',
    :api_key => api_key
  }
end

#to_sObject


17
18
19
# File 'app/models/fingerprint/sha1.rb', line 17

def to_s
  Digest::SHA1.hexdigest(fingerprint_source.to_s)
end

#unified_messageObject

filter memory addresses out of object strings example: “#<Object:0x007fa2b33d9458>” becomes “#<Object>”


38
39
40
# File 'app/models/fingerprint/sha1.rb', line 38

def unified_message
  notice.message.gsub(/(#<.+?):[0-9a-f]x[0-9a-f]+(>)/, '\1\2')
end