Class: Skyfall::Firehose::CommitMessage

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

Overview

Firehose message which includes one or more operations on records in the repo (a record was created, updated or deleted). In most cases this is a single record operation.

Most of the messages received from the firehose are of this type, and this is the type you will usually be most interested in.

Instance Method Summary collapse

Constructor Details

#initialize(type_object, data_object) ⇒ CommitMessage

Returns a new instance of CommitMessage.

Parameters:

  • type_object (Hash)

    first decoded CBOR frame with metadata

  • data_object (Hash)

    second decoded CBOR frame with payload

Raises:

  • (DecodeError)

    if the message doesn't include required data



26
27
28
29
# File 'lib/skyfall/firehose/commit_message.rb', line 26

def initialize(type_object, data_object)
  super
  check_if_not_nil 'seq', 'repo', 'commit', 'blocks', 'ops', 'time', 'rev'
end

Instance Method Details

#blocksOxygene::CARArchive

Returns commit data in the form of a parsed CAR archive.

Returns:

  • (Oxygene::CARArchive)

    commit data in the form of a parsed CAR archive



54
55
56
# File 'lib/skyfall/firehose/commit_message.rb', line 54

def blocks
  @blocks ||= Oxygene::CARArchive.new(@data_object['blocks'])
end

#commitOxygene::CID Also known as: cid

Returns CID (Content Identifier) of the commit.

Returns:

  • (Oxygene::CID)

    CID (Content Identifier) of the commit



47
48
49
# File 'lib/skyfall/firehose/commit_message.rb', line 47

def commit
  @commit ||= Oxygene::CID.from_cbor_tag(@data_object['commit'])
end

#operationsArray<Firehose::Operation>

Returns record operations (usually one) included in the commit.

Returns:



59
60
61
# File 'lib/skyfall/firehose/commit_message.rb', line 59

def operations
  @operations ||= @data_object['ops'].map { |op| Firehose::Operation.new(self, op) }
end

#prev_dataOxygene::CID?

Returns CID (Content Identifier) of data of the previous commit in the repo.

Returns:

  • (Oxygene::CID, nil)

    CID (Content Identifier) of data of the previous commit in the repo



42
43
44
# File 'lib/skyfall/firehose/commit_message.rb', line 42

def prev_data
  @prev_data ||= Oxygene::CID.from_cbor_tag(@data_object['prevData'])
end

#raw_record_for_operation(op) ⇒ Hash?

Looks up record data assigned to a given operation in the commit's CAR archive.

Parameters:

Returns:

  • (Hash, nil)


66
67
68
# File 'lib/skyfall/firehose/commit_message.rb', line 66

def raw_record_for_operation(op)
  op.cid && blocks.section_with_cid(op.cid)
end

#revString

Returns current revision of the repo.

Returns:

  • (String)

    current revision of the repo



32
33
34
# File 'lib/skyfall/firehose/commit_message.rb', line 32

def rev
  @data_object['rev']
end

#sinceString?

Returns revision of the previous commit in the repo.

Returns:

  • (String, nil)

    revision of the previous commit in the repo



37
38
39
# File 'lib/skyfall/firehose/commit_message.rb', line 37

def since
  @data_object['since']
end