Class: Skyfall::Firehose::Operation
- Inherits:
-
Object
- Object
- Skyfall::Firehose::Operation
- Defined in:
- lib/skyfall/firehose/operation.rb
Overview
A single record operation from a firehose commit event. An operation is a new record being created, or an existing record modified or deleted. It includes the URI and other details of the record in question, type of the action taken, and record data for "created" and "update" actions.
Note: when a record is deleted, the previous record data is not included in the commit, only its URI. This means that if you're tracking records which are referencing other records, e.g. follow, block, or like records, you need to store information about this referencing record including an URI or rkey, because in case of a delete, you will not get information about which post was unliked or which account was unfollowed, only which like/follow record was deleted.
At the moment, Skyfall doesn't parse the record data into any rich models specific for a given
record type with a convenient API, but simply returns them as Hash objects (see #raw_record).
In the future, a separate #record method might be added which returns a parsed record model.
Instance Method Summary collapse
-
#action ⇒ Symbol
Type of the operation (
:create,:updateor:delete). -
#cid ⇒ Oxygene::CID?
CID (Content Identifier) of the record (nil for delete operations).
-
#collection ⇒ String
Record collection NSID.
-
#initialize(message, json) ⇒ Operation
constructor
A new instance of Operation.
-
#inspect ⇒ String
Returns a string with a representation of the object for debugging purposes.
-
#path ⇒ String
Path part of the record URI (collection + rkey).
-
#raw_record ⇒ Hash?
Record data as a plain Ruby Hash (nil for delete operations).
-
#repo ⇒ String
(also: #did)
DID of the account/repository in which the operation happened.
-
#rkey ⇒ String
Record rkey.
-
#type ⇒ Symbol
Symbol short code of the collection, like
:bsky_post. -
#uri ⇒ String
Full AT URI of the record.
Constructor Details
#initialize(message, json) ⇒ Operation
Returns a new instance of Operation.
33 34 35 36 |
# File 'lib/skyfall/firehose/operation.rb', line 33 def initialize(, json) @message = @json = json end |
Instance Method Details
#action ⇒ Symbol
Returns type of the operation (:create, :update or :delete).
51 52 53 |
# File 'lib/skyfall/firehose/operation.rb', line 51 def action @action ||= @json['action'].to_sym end |
#cid ⇒ Oxygene::CID?
Returns CID (Content Identifier) of the record (nil for delete operations).
83 84 85 |
# File 'lib/skyfall/firehose/operation.rb', line 83 def cid @cid ||= @json['cid'] && Oxygene::CID.from_cbor_tag(@json['cid']) end |
#collection ⇒ String
Returns record collection NSID.
56 57 58 59 60 61 62 63 64 |
# File 'lib/skyfall/firehose/operation.rb', line 56 def collection @collection ||= begin path = @json['path'] slash = path.index('/') raise DecodeError, "Path doesn't contain a /: #{path}" if slash.nil? path[0...slash] end end |
#inspect ⇒ String
Returns a string with a representation of the object for debugging purposes.
105 106 107 108 |
# File 'lib/skyfall/firehose/operation.rb', line 105 def inspect vars = inspectable_variables.map { |v| "#{v}=#{instance_variable_get(v).inspect}" }.join(", ") "#<#{self.class}:0x#{object_id} #{vars}>" end |
#path ⇒ String
Returns path part of the record URI (collection + rkey).
46 47 48 |
# File 'lib/skyfall/firehose/operation.rb', line 46 def path @json['path'] end |
#raw_record ⇒ Hash?
Returns record data as a plain Ruby Hash (nil for delete operations).
88 89 90 |
# File 'lib/skyfall/firehose/operation.rb', line 88 def raw_record @raw_record ||= @message.raw_record_for_operation(self) end |
#repo ⇒ String Also known as: did
Returns DID of the account/repository in which the operation happened.
39 40 41 |
# File 'lib/skyfall/firehose/operation.rb', line 39 def repo @message.repo end |
#rkey ⇒ String
Returns record rkey.
67 68 69 70 71 72 73 74 75 |
# File 'lib/skyfall/firehose/operation.rb', line 67 def rkey @rkey ||= begin path = @json['path'] slash = path.index('/') raise DecodeError, "Path doesn't contain a /: #{path}" if slash.nil? path[(slash + 1)..-1] end end |
#type ⇒ Symbol
Symbol short code of the collection, like :bsky_post. If the collection NSID is not
recognized, the type is :unknown. The full NSID is always available through the
#collection property.
99 100 101 |
# File 'lib/skyfall/firehose/operation.rb', line 99 def type Collection.short_code(collection) end |
#uri ⇒ String
Returns full AT URI of the record.
78 79 80 |
# File 'lib/skyfall/firehose/operation.rb', line 78 def uri @uri ||= "at://#{repo}/#{path}" end |