Module: ZooStream

Defined in:
lib/zoo_stream.rb,
lib/zoo_stream/event.rb,
lib/zoo_stream/version.rb,
lib/zoo_stream/kinesis_publisher.rb

Defined Under Namespace

Classes: Event, KinesisPublisher

Constant Summary collapse

VERSION =
"1.1.0"

Class Method Summary collapse

Class Method Details

.default_publisherObject



37
38
39
40
41
# File 'lib/zoo_stream.rb', line 37

def self.default_publisher
  if ENV.key?("ZOO_STREAM_KINESIS_STREAM_NAME")
    ZooStream::KinesisPublisher.new
  end
end

.publish(event: nil, data: nil, linked: {}, shard_by: nil) ⇒ Object

Publishes an event

Parameters:

  • event (String) (defaults to: nil)

    the event type

  • data (Hash) (defaults to: nil)

    the event data

  • linked (Hash) (defaults to: {})

    related models to the data

  • shard_by (String) (defaults to: nil)

    if present, reader order will be guaranteed within this shard. If left blank, the entire stream will always be a single shard.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
# File 'lib/zoo_stream.rb', line 12

def self.publish(event: nil, data: nil, linked: {}, shard_by: nil)
  raise ArgumentError, "Must specify event" unless event
  raise ArgumentError, "Must specify data" unless data

  return unless publisher
  event = Event.new(source, event, data, linked)
  publisher.publish(event, shard_by: (shard_by || event.type).to_s)
end

.publisherObject



21
22
23
# File 'lib/zoo_stream.rb', line 21

def self.publisher
  @publisher || default_publisher
end

.publisher=(publisher) ⇒ Object



25
26
27
# File 'lib/zoo_stream.rb', line 25

def self.publisher=(publisher)
  @publisher = publisher
end

.sourceObject



29
30
31
# File 'lib/zoo_stream.rb', line 29

def self.source
  @source || ENV.fetch("ZOO_STREAM_SOURCE")
end

.source=(source) ⇒ Object



33
34
35
# File 'lib/zoo_stream.rb', line 33

def self.source=(source)
  @source = source
end