Class: Proscenium::Resolver
- Inherits:
-
ActiveSupport::CurrentAttributes
- Object
- ActiveSupport::CurrentAttributes
- Proscenium::Resolver
- Defined in:
- lib/proscenium/resolver.rb
Class Method Summary collapse
-
.resolve(path, as_array: false) ⇒ String
Resolve the given ‘path` to a fully qualified URL path.
Class Method Details
.resolve(path, as_array: false) ⇒ String
Resolve the given ‘path` to a fully qualified URL path.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/proscenium/resolver.rb', line 16 def self.resolve(path, as_array: false) self.resolved ||= {} if path.start_with?('./', '../') raise ArgumentError, '`path` must be an absolute file system or URL path' end self.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}"] elsif path.start_with?("#{Rails.root}/") vpath = path.delete_prefix(Rails.root.to_s) [Proscenium::Manifest[vpath], vpath] else [Proscenium::Manifest[path], Builder.resolve(path)] end as_array ? self.resolved[path] : self.resolved[path][0] || self.resolved[path][1] end |