The inner class for the 'ack' operational property
The object's message, :sender, :via, :time
The object's message, :sender, :via, :time
The object's message, :sender, :via, :time
The object's message, :sender, :via, :time
Construct an instance from the values in the specified hash
.
# File lib/arborist/node/ack.rb, line 12
def self::from_hash( hash )
hash = symbolify_keys( hash )
message = hash.delete( :message ) or raise ArgumentError, "Missing required ACK message"
sender = hash.delete( :sender ) or raise ArgumentError, "Missing required ACK sender"
if hash[:time]
hash[:time] = Time.at( hash[:time] ) if hash[:time].is_a?( Numeric )
hash[:time] = Time.parse( hash[:time] ) unless hash[:time].is_a?( Time )
end
return new( message, sender, **hash )
end
Create a new acknowledgement
# File lib/arborist/node/ack.rb, line 28
def initialize( message, sender, via: nil, time: nil )
time ||= Time.now
@message = message
@sender = sender
@via = via
@time = time.to_time
end
Returns true if the other
object is an Ack with the same values.
# File lib/arborist/node/ack.rb, line 64
def ==( other )
return other.is_a?( self.class ) &&
self.to_h == other.to_h
end
Return a string description of the acknowledgement for logging and inspection.
# File lib/arborist/node/ack.rb, line 43
def description
return "by %s%s -- %s" % [
self.sender,
self.via ? " via #{self.via}" : '',
self.message
]
end
Return the Ack as a Hash.
# File lib/arborist/node/ack.rb, line 53
def to_h( * )
return {
message: self.message,
sender: self.sender,
via: self.via,
time: self.time.iso8601,
}
end