Class: Segment::Analytics::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/segment/analytics/message.rb

Overview

Represents a message to be sent to the API

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Message

Returns a new instance of Message.



7
8
9
# File 'lib/segment/analytics/message.rb', line 7

def initialize(hash)
  @hash = hash
end

Instance Method Details

#json_sizeObject



15
16
17
# File 'lib/segment/analytics/message.rb', line 15

def json_size
  to_json.bytesize
end

#to_json(*args) ⇒ Object

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



21
22
23
# File 'lib/segment/analytics/message.rb', line 21

def to_json(*args)
  @json ||= @hash.to_json(*args)
end

#too_big?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/segment/analytics/message.rb', line 11

def too_big?
  json_size > Defaults::Message::MAX_BYTES
end