class EventStream::Event

Events are immutable collections of fields with convenience methods for accessing and json serialization

Public Class Methods

from_json(json_event) click to toggle source

Parses an event object from JSON @param json_event [String] The JSON event representation, such as created by `event.to_json` @return [Event]

# File lib/event_stream/event.rb, line 32
def self.from_json(json_event)
  new(JSON.parse(json_event))
end
new(fields) click to toggle source

@param fields [Hash<Symbol, Object>] The attributes of this event

# File lib/event_stream/event.rb, line 8
def initialize(fields)
  @fields = Hash[fields.map { |k,v| [k.to_sym, v] }].freeze
end

Public Instance Methods

[](key) click to toggle source

An alternate field accessor @param key [Symbol] @return [Object]

# File lib/event_stream/event.rb, line 15
def [](key)
  @fields[key.to_sym]
end
method_missing(method_name, *args) click to toggle source
Calls superclass method
# File lib/event_stream/event.rb, line 36
def method_missing(method_name, *args)
  @fields.has_key?(method_name) ? @fields[method_name] : super
end
respond_to_missing?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/event_stream/event.rb, line 40
def respond_to_missing?(method_name, include_private = false)
  @fields.has_key?(method_name) || super
end
to_h() click to toggle source

@return [Hash<Symbol, Object>]

# File lib/event_stream/event.rb, line 20
def to_h
  @fields
end
to_json() click to toggle source

@return [String]

# File lib/event_stream/event.rb, line 25
def to_json
  JSON.dump(to_h)
end