Class: Proscenium::Resolver
- Inherits:
-
Object
- Object
- Proscenium::Resolver
- Defined in:
- lib/proscenium/resolver.rb
Class Method Summary collapse
- .reset ⇒ Object
-
.resolve(path, as_array: false) ⇒ String+
Resolve the given ‘path` to a fully qualified URL path.
Class Method Details
.reset ⇒ Object
31 32 33 |
# File 'lib/proscenium/resolver.rb', line 31 def self.reset self.resolved = {} end |
.resolve(path, as_array: false) ⇒ String+
Resolve the given ‘path` to a fully qualified URL path.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/proscenium/resolver.rb', line 13 def self.resolve(path, as_array: false) if path.start_with?('./', '../') raise ArgumentError, '`path` must be an absolute file system or URL path' end resolved[path] ||= if (gem = BundledGems.paths.find { |_, v| path.start_with? "#{v}/" }) vpath = path.sub(/^#{gem.last}/, "@rubygems/#{gem.first}") [Proscenium::Manifest[vpath], "/node_modules/#{vpath}", path] elsif path.start_with?("#{Rails.root}/") vpath = path.delete_prefix(Rails.root.to_s) [Proscenium::Manifest[vpath], vpath, path] else [Proscenium::Manifest[path], *Builder.resolve(path)] end as_array ? resolved[path] : resolved[path][0] || resolved[path][1] end |