module ContentAddressableFile::SharedInterface

Public Instance Methods

==(other) click to toggle source

Returns true if the other File has the same id

# File lib/content_addressable_file/shared_interface.rb, line 35
def ==(other)
  other.respond_to?(:digest) && content_addressable == other.content_addressable
end
Also aliased as: eql?
content_addressable() click to toggle source
# File lib/content_addressable_file/shared_interface.rb, line 7
def content_addressable
  @content_addressable ||= String(id).rpartition('/').last
end
decode() click to toggle source

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.

# File lib/content_addressable_file/shared_interface.rb, line 15
def decode
  @decode ||= Multihashes.decode([content_addressable].pack('H*'))
end
digest() click to toggle source

The deocode digest as a byte array

# File lib/content_addressable_file/shared_interface.rb, line 20
def digest
  decode[:digest]
end
digest_hash_function() click to toggle source

The decode hash function

# File lib/content_addressable_file/shared_interface.rb, line 30
def digest_hash_function
  decode[:hash_function]
end
digest_length() click to toggle source

The decode digest length

# File lib/content_addressable_file/shared_interface.rb, line 25
def digest_length
  decode[:length]
end
eql?(other)
Alias for: ==
hash() click to toggle source

Enables using File objects as hash keys.

# File lib/content_addressable_file/shared_interface.rb, line 41
def hash
  [content_addressable].hash
end