Class: JS::RequireRemote::URLResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/js/require_remote/url_resolver.rb

Overview

When require_relative is called within a running Ruby script, the URL is resolved from a relative file path based on the URL of the running Ruby script. It uses a stack to store URLs of running Ruby Script. Push the URL onto the stack before executing the new script. Then pop it when the script has finished executing.

Instance Method Summary collapse

Constructor Details

#initialize(base_url) ⇒ URLResolver

Returns a new instance of URLResolver.



11
12
13
# File 'lib/js/require_remote/url_resolver.rb', line 11

def initialize(base_url)
  @url_stack = [base_url]
end

Instance Method Details

#get_location(relative_feature) ⇒ Object



15
16
17
18
19
# File 'lib/js/require_remote/url_resolver.rb', line 15

def get_location(relative_feature)
  filename = filename_from(relative_feature)
  url = resolve(filename)
  ScriptLocation.new(url, filename)
end

#inspectObject



29
30
31
# File 'lib/js/require_remote/url_resolver.rb', line 29

def inspect
  "#{self.class}(#{@url_stack})"
end

#popObject



25
26
27
# File 'lib/js/require_remote/url_resolver.rb', line 25

def pop()
  @url_stack.pop
end

#push(url) ⇒ Object



21
22
23
# File 'lib/js/require_remote/url_resolver.rb', line 21

def push(url)
  @url_stack.push url
end