Class: Sentry::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/sentry/attachment.rb

Constant Summary collapse

PathNotFoundError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bytes: nil, filename: nil, content_type: nil, path: nil) ⇒ Attachment

Returns a new instance of Attachment.



9
10
11
12
13
14
# File 'lib/sentry/attachment.rb', line 9

def initialize(bytes: nil, filename: nil, content_type: nil, path: nil)
  @bytes = bytes
  @filename = filename || infer_filename(path)
  @path = path
  @content_type = content_type
end

Instance Attribute Details

#bytesObject (readonly)

Returns the value of attribute bytes.



7
8
9
# File 'lib/sentry/attachment.rb', line 7

def bytes
  @bytes
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



7
8
9
# File 'lib/sentry/attachment.rb', line 7

def content_type
  @content_type
end

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'lib/sentry/attachment.rb', line 7

def filename
  @filename
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/sentry/attachment.rb', line 7

def path
  @path
end

Instance Method Details

#payloadObject



20
21
22
23
24
25
26
27
28
# File 'lib/sentry/attachment.rb', line 20

def payload
  @payload ||= if bytes
    bytes
  else
    File.binread(path)
  end
rescue Errno::ENOENT
  raise PathNotFoundError, "Failed to read attachment file, file not found: #{path}"
end

#to_envelope_headersObject



16
17
18
# File 'lib/sentry/attachment.rb', line 16

def to_envelope_headers
  { type: "attachment", filename: filename, content_type: content_type, length: payload.bytesize }
end