Module: Shrine::Plugins::ContentAddressable::InstanceMethods

Defined in:
lib/shrine/plugins/content_addressable.rb

Instance Method Summary collapse

Instance Method Details

#content_addressable_hashObject



61
62
63
# File 'lib/shrine/plugins/content_addressable.rb', line 61

def content_addressable_hash
  (opts[:content_addressable_hash] || 'sha256').to_sym
end

#content_addressable_hex(io) ⇒ Object



72
73
74
75
76
77
# File 'lib/shrine/plugins/content_addressable.rb', line 72

def content_addressable_hex(io)
  digest = calculate_signature(io, content_addressable_hash, format: :none)
  Multihashes.encode(digest, content_addressable_multihash)
             .unpack('H*')
             .first
end

#content_addressable_multihashObject



65
66
67
68
69
70
# File 'lib/shrine/plugins/content_addressable.rb', line 65

def content_addressable_multihash
  String(
    opts[:content_addressable_multihash] ||
    MULTIHASH_LOOKUP.fetch(content_addressable_hash)
  )
end

#generate_location(io, _) ⇒ Object



79
80
81
82
83
# File 'lib/shrine/plugins/content_addressable.rb', line 79

def generate_location(io, _)
  [opts[:content_addressable_prefix], content_addressable_hex(io)]
    .compact
    .join('/')
end