Module: ContentAddressableFile::SharedInterface
- Defined in:
- lib/content_addressable_file/shared_interface.rb
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Returns true if the other File has the same id.
- #content_addressable ⇒ Object
-
#decode ⇒ Object
Tries to decode the multihash.
-
#digest ⇒ Object
The #deocode digest as a byte array.
-
#digest_hash_function ⇒ Object
The #decode hash function.
-
#digest_length ⇒ Object
The #decode digest length.
-
#hash ⇒ Object
Enables using File objects as hash keys.
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Returns true if the other File has the same id
35 36 37 |
# File 'lib/content_addressable_file/shared_interface.rb', line 35 def ==(other) other.respond_to?(:digest) && content_addressable == other.content_addressable end |
#content_addressable ⇒ Object
7 8 9 |
# File 'lib/content_addressable_file/shared_interface.rb', line 7 def content_addressable @content_addressable ||= String(id).rpartition('/').last end |
#decode ⇒ Object
Tries to decode the multihash. This is a good check to see if the given id is actually a content-addressable, but also easy to “fake”, as the only way to be certain that the id is a content addressable is actually getting the file and hashing it again.
15 16 17 |
# File 'lib/content_addressable_file/shared_interface.rb', line 15 def decode @decode ||= Multihashes.decode([content_addressable].pack('H*')) end |
#digest ⇒ Object
The #deocode digest as a byte array
20 21 22 |
# File 'lib/content_addressable_file/shared_interface.rb', line 20 def digest decode[:digest] end |
#digest_hash_function ⇒ Object
The #decode hash function
30 31 32 |
# File 'lib/content_addressable_file/shared_interface.rb', line 30 def digest_hash_function decode[:hash_function] end |
#digest_length ⇒ Object
The #decode digest length
25 26 27 |
# File 'lib/content_addressable_file/shared_interface.rb', line 25 def digest_length decode[:length] end |
#hash ⇒ Object
Enables using File objects as hash keys.
41 42 43 |
# File 'lib/content_addressable_file/shared_interface.rb', line 41 def hash [content_addressable].hash end |