class Segment::Analytics::Message

Represents a message to be sent to the API

Public Class Methods

new(hash) click to toggle source
# File lib/segment/analytics/message.rb, line 7
def initialize(hash)
  @hash = hash
end

Public Instance Methods

json_size() click to toggle source
# File lib/segment/analytics/message.rb, line 15
def json_size
  to_json.bytesize
end
to_json(*args) click to toggle source

Since the hash is expected to not be modified (set at initialization), the JSON version can be cached after the first computation.

# File lib/segment/analytics/message.rb, line 21
def to_json(*args)
  @json ||= @hash.to_json(*args)
end
too_big?() click to toggle source
# File lib/segment/analytics/message.rb, line 11
def too_big?
  json_size > Defaults::Message::MAX_BYTES
end