Class: SolidErrors::Frontend::SourceMapper
- Inherits:
-
Object
- Object
- SolidErrors::Frontend::SourceMapper
- Defined in:
- lib/solid_errors/frontend/source_mapper.rb
Overview
Resolves the URL of a served asset back to the source file it was built from.
No source maps are involved and none are needed: with importmap + Propshaft there is no bundling or minification, so line numbers in the served asset match the source file exactly. All that has to be undone is the digest Propshaft splices into the filename (application-abc12345.js).
Returning an absolute path under Rails.root is what lets an error backend recognise the frame as application code and show the surrounding source.
Constant Summary collapse
- MAX_CACHE_SIZE =
500
Instance Method Summary collapse
-
#initialize(host: nil) ⇒ SourceMapper
constructor
A new instance of SourceMapper.
-
#resolve(url) ⇒ String?
Absolute path of the source file, if it can be found.
Constructor Details
#initialize(host: nil) ⇒ SourceMapper
Returns a new instance of SourceMapper.
18 19 20 21 |
# File 'lib/solid_errors/frontend/source_mapper.rb', line 18 def initialize(host: nil) @host = host @cache = {} end |
Instance Method Details
#resolve(url) ⇒ String?
Returns absolute path of the source file, if it can be found.
24 25 26 27 28 29 30 31 32 |
# File 'lib/solid_errors/frontend/source_mapper.rb', line 24 def resolve(url) return nil if url.nil? @cache.fetch(url) do path = lookup(url) @cache.clear if @cache.size >= MAX_CACHE_SIZE @cache[url] = path end end |