class HTTPShell::Environment

Attributes

variables[R]
working_path[RW]

Public Class Methods

new() click to toggle source
# File lib/httpshell.rb, line 8
def initialize
  @variables = {}
  @working_path = "http://"
end

Public Instance Methods

cd(path) click to toggle source
# File lib/httpshell.rb, line 13
def cd(path)
  if /^(http|https|file):\/\//i =~ path
    cd_absolutely(path)
  else
    cd_relatively(path)
  end
end

Private Instance Methods

cd_absolutely(path) click to toggle source
# File lib/httpshell.rb, line 39
def cd_absolutely(path)
  if not /^(http|https|file):\/\/$/i =~ path
    path = path.sub /\/$/, ''
  end
  
  @working_path = path
end
cd_relatively(path) click to toggle source
# File lib/httpshell.rb, line 22
def cd_relatively(path)
  path = path.sub /^\/+/, ''
  path = path.sub /\/+$/, ''
  
  if path == '..'
    @working_path = @working_path.sub /\/[^\/]+$/, ''
  elsif path == '.'
    @working_path = @working_path
  else
    if /^(http|https|file):\/\/$/i =~ @working_path
      @working_path = "#{@working_path}#{path}"
    else
      @working_path = "#{@working_path}/#{path}"
    end
  end
end