Class: URI::HTTP

Inherits:
Object show all
Defined in:
lib/mumukit/platform/uri.rb

Instance Method Summary collapse

Instance Method Details

#rebuild(updates) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/mumukit/platform/uri.rb', line 20

def rebuild(updates)
  self.class.build({
    scheme: scheme,
    host: host,
    path: path,
    query: query,
    port: port,
    fragment: fragment}.merge(updates))
end

#subdominate(subdomain) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/mumukit/platform/uri.rb', line 2

def subdominate(subdomain)
  if host.start_with? 'www.'
    new_host = host.gsub('www.', "www.#{subdomain}.")
  else
    new_host = "#{subdomain}.#{host}"
  end
  rebuild(host: new_host)
end

#subroute(route) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/mumukit/platform/uri.rb', line 11

def subroute(route)
  if path.start_with? '/'
    new_path = "/#{route}#{path}"
  else
    new_path = "/#{route}/#{path}"
  end
  rebuild(path: new_path)
end

#url_for(path) ⇒ Object



30
31
32
# File 'lib/mumukit/platform/uri.rb', line 30

def url_for(path)
  URI.join(self, path).to_s
end