Module: Kernel

Defined in:
lib/http_require.rb

Defined Under Namespace

Classes: HttpLoadError

Constant Summary collapse

@@http_require_base =
nil

Instance Method Summary collapse

Instance Method Details

#http_require(path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/http_require.rb', line 15

def http_require(path)
  uri = path.is_a?(URI) ? path : URI.parse(path)

  content = uri.read

  with_http_require_base(File.dirname(uri.to_s)) do
    eval(content, binding, uri.to_s)
  end

end

#require(path) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/http_require.rb', line 27

def require(path)
  uri = URI.parse(path) rescue nil
  return http_require(uri) if uri.is_a?(URI) && (uri.class != URI::Generic)

  require_without_http(path)

rescue LoadError => e
  if @http_require_base
    path += ".rb" unless path[-3..-1] == ".rb"
    http_require "#{@http_require_base}/#{path}"
  else
    raise e
  end
end

#require_without_httpObject



26
# File 'lib/http_require.rb', line 26

alias :require_without_http :require

#with_http_require_base(base) ⇒ Object



8
9
10
11
12
13
# File 'lib/http_require.rb', line 8

def with_http_require_base(base)
  base, @http_require_base = @http_require_base, base
  yield
ensure
  @http_require_base = base
end