Class: Xhive::Router::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/xhive/router/base.rb

Class Method Summary collapse

Class Method Details

.match(url) ⇒ Object

Public: returns the route that matches the url.

url - The String containing the url to match.

Returns: an Route object.



10
11
12
# File 'lib/xhive/router/base.rb', line 10

def self.match(url)
  Route.find(url)
end

.route_for(controller, action) ⇒ Object

Public: returns the route definition for a controller#action pair.

controller - The String containing the controller name. action - The String containing the action name.

Returns: the route definition. e.g. ‘pages/:id/show’.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/xhive/router/base.rb', line 21

def self.route_for(controller, action)
  url = ''
  routes = normalized_routes
  url = routes.to_a.select {|route| route[:end_point] == "#{controller}##{action}"}.first.fetch(:path)
  url = url.gsub('(.:format)', '')
  url
rescue
  Rails.logger.error "#{Error.class.name}:#{controller}##{action}"
ensure
  return url
end