Class: Gloo::WebSvr::Routing::ShowRoutes

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo/web_svr/routing/show_routes.rb

Constant Summary collapse

SEGMENT_DIVIDER =
'/'.freeze
RETURN =
"\n".freeze

Instance Method Summary collapse

Constructor Details

#initialize(engine) ⇒ ShowRoutes

Set up the web server.



23
24
25
26
# File 'lib/gloo/web_svr/routing/show_routes.rb', line 23

def initialize( engine )
  @engine = engine
  @log = @engine.log
end

Instance Method Details

#add_container_routes(can, route_path) ⇒ Object

Show the routes in the given container. This is a recursive function travese the object tree.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gloo/web_svr/routing/show_routes.rb', line 50

def add_container_routes can, route_path
  can.children.each do |obj|
    if obj.class == Gloo::Objs::Container
      add_container_routes obj, "#{route_path}#{obj.name}#{SEGMENT_DIVIDER}"
    elsif obj.class == Gloo::Objs::Page
      route = "#{route_path}#{obj.name}"
      @found_routes << [ obj.name, obj.pn, route, Gloo::WebSvr::WebMethod::GET ]

      # If the method is POST, add a route alias for the create.
      if obj.name.eql? ResourceRouter::POST_ROUTE
        @found_routes << [ '', '', route_path, Gloo::WebSvr::WebMethod::POST ]
      elsif obj.name.eql? ResourceRouter::UPDATE
        @found_routes << [ '', '', route_path, Gloo::WebSvr::WebMethod::PATCH ]
      elsif obj.name.eql? ResourceRouter::DELETE
        @found_routes << [ '', '', route_path, Gloo::WebSvr::WebMethod::DELETE ]
      end
    end
  end
end

#headersObject

Get the table headers.



88
89
90
# File 'lib/gloo/web_svr/routing/show_routes.rb', line 88

def headers
  return [ 'Obj Name', 'Obj Path', 'Route', 'Method' ]
end

#show(page_container) ⇒ Object

Show all available routes.



36
37
38
39
40
41
42
43
44
# File 'lib/gloo/web_svr/routing/show_routes.rb', line 36

def show page_container
  @log.debug "showing routes"

  @found_routes = []
  @log.debug "building route table"
  add_container_routes( page_container, SEGMENT_DIVIDER )

  show_table
end

#show_tableObject

Show the Routes title.



78
79
80
81
82
83
# File 'lib/gloo/web_svr/routing/show_routes.rb', line 78

def show_table
  puts RETURN
  title = "Routes in Running Web App"
  @engine.platform.table.show headers, @found_routes, title
  puts RETURN
end