Class: URI::HTTP

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

Instance Method Summary collapse

Instance Method Details

#rebuild(updates, fragmented: false) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mumukit/platform/uri.rb', line 20

def rebuild(updates, fragmented: false)
  if fragmented && fragment
    fragment = "#{self.fragment}/#{updates[:path]}/".squeeze('/')
    updates = updates.except(:path)
  else
    fragment = self.fragment
  end

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

#subdominate(subdomain, **options) ⇒ Object



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

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

#tenantize(route, fragmented: false) ⇒ Object



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

def tenantize(route, fragmented: false)
  if fragmented && fragment
    new_path = route
  else
    new_path = "#{path.chomp('/')}/#{route}/"
  end
  rebuild({path: new_path}, fragmented: fragmented)
end

#url_for(path) ⇒ Object



37
38
39
# File 'lib/mumukit/platform/uri.rb', line 37

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