Class: Skyfall::Jetstream::CommitMessage

Inherits:
Message
  • Object
show all
Defined in:
lib/skyfall/jetstream/commit_message.rb

Overview

Jetstream message which includes a single operation on a record in the repo (a record was created, updated or deleted). Most of the messages received from Jetstream are of this type, and this is the type you will usually be most interested in.

Instance Attribute Summary

Attributes inherited from Message

#did, #json, #time_us, #type

Instance Method Summary collapse

Methods inherited from Message

new, #time, #unknown?

Constructor Details

#initialize(json) ⇒ CommitMessage

Returns a new instance of CommitMessage.

Parameters:

  • json (Hash)

    message JSON decoded from the websocket message

Raises:

  • (DecodeError)

    if the message doesn’t include required data



22
23
24
25
26
27
28
# File 'lib/skyfall/jetstream/commit_message.rb', line 22

def initialize(json)
  raise DecodeError.new("Missing event details (commit)") if json['commit'].nil?

  %w(collection rkey operation).each { |f| raise DecodeError.new("Missing event details (#{f})") if json['commit'][f].nil? }

  super
end

Instance Method Details

#operationJetstream::Operation Also known as: op

Returns the record operation included in the commit.



33
34
35
# File 'lib/skyfall/jetstream/commit_message.rb', line 33

def operation
  @operation ||= Jetstream::Operation.new(self, json['commit'])
end

#operationsArray<Jetstream::Operation>

Returns record operations included in the commit. Currently a :commit message from Jetstream always includes exactly one operation, but for compatibility with Firehose‘s API it’s also returned in an array here.

Returns:



45
46
47
# File 'lib/skyfall/jetstream/commit_message.rb', line 45

def operations
  [operation]
end