Class: Sentry::Attachment
- Inherits:
-
Object
- Object
- Sentry::Attachment
- Defined in:
- lib/sentry/attachment.rb
Constant Summary collapse
- PathNotFoundError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(bytes: nil, filename: nil, content_type: nil, path: nil) ⇒ Attachment
constructor
A new instance of Attachment.
- #payload ⇒ Object
- #to_envelope_headers ⇒ Object
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
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
7 8 9 |
# File 'lib/sentry/attachment.rb', line 7 def bytes @bytes end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
7 8 9 |
# File 'lib/sentry/attachment.rb', line 7 def content_type @content_type end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/sentry/attachment.rb', line 7 def filename @filename end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/sentry/attachment.rb', line 7 def path @path end |
Instance Method Details
#payload ⇒ Object
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_headers ⇒ Object
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 |