Class: Skyfall::Firehose::CommitMessage

Inherits:
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 Attribute Summary

Attributes inherited from Message

#data_object, #did, #seq, #type, #type_object

Instance Method Summary collapse

Methods inherited from Message

#inspect, new, #time, #unknown?

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



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

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

Instance Method Details

#blocksSkyfall::CarArchive

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

Returns:



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

def blocks
  @blocks ||= CarArchive.new(@data_object['blocks'])
end

#commitCID

Returns CID (Content Identifier) of the commit.

Returns:

  • (CID)

    CID (Content Identifier) of the commit



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

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

#operationsArray<Firehose::Operation>

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

Returns:



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

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

#prev_dataCID?

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

Returns:

  • (CID, nil)

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



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

def prev_data
  @prev_data ||= 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)


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

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



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

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



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

def since
  @data_object['since']
end