Module: Audioproxy::Rails::BlobResolver::DiskLayout
- Defined in:
- lib/audioproxy/rails/blob_resolver.rb
Overview
The Disk service hides its layout behind DiskService#path_for: a file for key "wxyz9876" lives at Top Level Namespace/wx/yz/wxyz9876, under two subdirectories hashed out of the key itself. The proxy is handed the path relative to its own AP_LOCAL_ROOT, so the gem has to reproduce that rule — which makes it the one piece of private-ish Rails API this gem depends on, and the reason it lives alone in a module with a contract test against the real DiskService (D3).
Class Method Summary collapse
Class Method Details
.relative_path_for(key) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/audioproxy/rails/blob_resolver.rb', line 121 def relative_path_for(key) string = String.try_convert(key) if string.nil? || string.empty? raise ArgumentError, "an ActiveStorage blob key must be a non-empty String, got #{key.inspect}" end reject_unsafe(string) # folder_for can produce an empty middle segment ("ab" gives "ab/"), # and a key may carry its own separators. DiskService never sees # either, because it hands the join to File.expand_path, which # collapses them; reproducing the layout means reproducing that # normalization too, or a key like "ab" resolves to "ab//ab" here # and "ab/ab" on disk. cleanpath is the collapse without expand_path's # trip through the actual filesystem root. Pathname.new(File.join(folder_for(string), string)).cleanpath.to_s.delete_prefix("/") end |