Class: Igniter::Extensions::Contracts::ContentAddressing::ContentKey
- Inherits:
-
Object
- Object
- Igniter::Extensions::Contracts::ContentAddressing::ContentKey
- Defined in:
- lib/igniter/extensions/contracts/content_addressing/content_key.rb
Instance Attribute Summary collapse
-
#hex ⇒ Object
readonly
Returns the value of attribute hex.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(hex) ⇒ ContentKey
constructor
A new instance of ContentKey.
- #to_s ⇒ Object
Constructor Details
#initialize(hex) ⇒ ContentKey
Returns a new instance of ContentKey.
12 13 14 15 |
# File 'lib/igniter/extensions/contracts/content_addressing/content_key.rb', line 12 def initialize(hex) @hex = hex.freeze freeze end |
Instance Attribute Details
#hex ⇒ Object (readonly)
Returns the value of attribute hex.
10 11 12 |
# File 'lib/igniter/extensions/contracts/content_addressing/content_key.rb', line 10 def hex @hex end |
Class Method Details
.compute(fingerprint:, inputs:) ⇒ Object
32 33 34 35 |
# File 'lib/igniter/extensions/contracts/content_addressing/content_key.rb', line 32 def compute(fingerprint:, inputs:) payload = stable_serialize(inputs) new(Digest::SHA256.hexdigest("#{fingerprint}\x00#{payload}")[0..23]) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
21 22 23 |
# File 'lib/igniter/extensions/contracts/content_addressing/content_key.rb', line 21 def ==(other) other.is_a?(self.class) && other.hex == hex end |
#hash ⇒ Object
27 28 29 |
# File 'lib/igniter/extensions/contracts/content_addressing/content_key.rb', line 27 def hash hex.hash end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/igniter/extensions/contracts/content_addressing/content_key.rb', line 17 def to_s "ca:#{hex}" end |