Class: Rollbar::Encoding::Encoder
- Inherits:
-
Object
- Object
- Rollbar::Encoding::Encoder
- Defined in:
- lib/rollbar/encoding/encoder.rb
Constant Summary collapse
- ALL_ENCODINGS =
[::Encoding::UTF_8, ::Encoding::ISO_8859_1, ::Encoding::ASCII_8BIT, ::Encoding::US_ASCII]
- ASCII_ENCODINGS =
[::Encoding::US_ASCII, ::Encoding::ASCII_8BIT, ::Encoding::ISO_8859_1]
- ENCODING_OPTIONS =
{ :invalid => :replace, :undef => :replace, :replace => '' }
- UTF8 =
'UTF-8'.freeze
- BINARY =
'binary'.freeze
Instance Attribute Summary collapse
-
#object ⇒ Object
Returns the value of attribute object.
Instance Method Summary collapse
- #encode ⇒ Object
-
#initialize(object) ⇒ Encoder
constructor
A new instance of Encoder.
Constructor Details
#initialize(object) ⇒ Encoder
Returns a new instance of Encoder.
12 13 14 |
# File 'lib/rollbar/encoding/encoder.rb', line 12 def initialize(object) @object = object end |
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
10 11 12 |
# File 'lib/rollbar/encoding/encoder.rb', line 10 def object @object end |
Instance Method Details
#encode ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rollbar/encoding/encoder.rb', line 16 def encode value = object.to_s encoding = value.encoding # This will be most of cases so avoid force anything for them if encoding == ::Encoding::UTF_8 && value.valid_encoding? encoded_value = value else encoded_value = force_encoding(value).encode(*encoding_args(value)) end object.is_a?(Symbol) ? encoded_value.to_sym : encoded_value end |