Class: Useless::Doc::Router::Default

Inherits:
Object
  • Object
show all
Includes:
Useless::Doc::Router
Defined in:
lib/useless/doc/router.rb

Instance Method Summary collapse

Methods included from Useless::Doc::Router

default, uri_for

Constructor Details

#initialize(*supported_urls) ⇒ Default

Returns a new instance of Default.



33
34
35
# File 'lib/useless/doc/router.rb', line 33

def initialize(*supported_urls)
  @supported_urls = supported_urls
end

Instance Method Details

#api_for_doc(url) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/useless/doc/router.rb', line 48

def api_for_doc(url)
  uri = Router.uri_for(url)
  host = uri.host
  parts = host.split('.')
  parts.slice!(-3) if parts[-3] == 'doc'
  new_host = parts.join('.')
  new_url = "#{uri.scheme}://#{new_host}#{uri.path}"
  new_url if supported_url?(new_url)
end

#doc_for_api(url) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/useless/doc/router.rb', line 37

def doc_for_api(url)
  return nil unless supported_url?(url)
  uri = Router.uri_for(url)
  host = uri.host
  new_host = host.
    split('.').
    insert(-3, 'doc').
    join('.')
  "#{uri.scheme}://#{new_host}#{uri.path}"
end