Module: Apicraft::Web::Router

Defined in:
lib/apicraft/web/router.rb

Overview

Managing routes and view paths

Constant Summary collapse

WEB_ROOT =
File.expand_path(
  "#{File.dirname(__FILE__)}/../../../web"
)
IMAGES_DIR =
"#{WEB_ROOT}/assets/images"

Class Method Summary collapse

Class Method Details

.add(path, view_path) ⇒ Object



41
42
43
44
45
46
# File 'lib/apicraft/web/router.rb', line 41

def self.add(path, view_path)
  routes[path] = {
    action: :contract,
    view_path: view_path
  }
end

.contract_urlsObject



63
64
65
66
67
68
69
70
# File 'lib/apicraft/web/router.rb', line 63

def self.contract_urls
  contract_keys = routes.select do |_k, v|
    v[:action] == :contract
  end.keys
  contract_keys.map do |k|
    "#{Router.namespace}#{k}"
  end
end

.load_response!(_method, path) ⇒ Object



48
49
50
51
52
53
# File 'lib/apicraft/web/router.rb', line 48

def self.load_response!(_method, path)
  Actions.send(
    routes[path][:action],
    routes[path][:view_path]
  )
end

.namespaceObject



59
60
61
# File 'lib/apicraft/web/router.rb', line 59

def self.namespace
  @namespace
end

.namespace=(namespace) ⇒ Object



55
56
57
# File 'lib/apicraft/web/router.rb', line 55

def self.namespace=(namespace)
  @namespace = namespace
end

.routesObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/apicraft/web/router.rb', line 12

def self.routes
  @routes ||= {
    "/": {
      action: :render_erb,
      view_path: "#{WEB_ROOT}/views/index.erb"
    },
    "/swaggerdoc": {
      action: :render_erb,
      view_path: "#{WEB_ROOT}/views/swaggerdoc.erb"
    },
    "/redoc": {
      action: :render_erb,
      view_path: "#{WEB_ROOT}/views/redoc.erb"
    },
    "/rapidoc": {
      action: :render_erb,
      view_path: "#{WEB_ROOT}/views/rapidoc.erb"
    },
    "/assets/images/thumb.png": {
      action: :images,
      view_path: "#{IMAGES_DIR}/apicraft_thumb.png"
    },
    "/assets/images/logo.png": {
      action: :images,
      view_path: "#{IMAGES_DIR}/apicraft.png"
    }
  }.with_indifferent_access
end