Class: Jun::ActionDispatch::Routing::Route

Inherits:
Struct
  • Object
show all
Defined in:
lib/jun/action_dispatch/routing/route_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionObject

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



8
9
10
# File 'lib/jun/action_dispatch/routing/route_set.rb', line 8

def action
  @action
end

#controllerObject

Returns the value of attribute controller

Returns:

  • (Object)

    the current value of controller



8
9
10
# File 'lib/jun/action_dispatch/routing/route_set.rb', line 8

def controller
  @controller
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



8
9
10
# File 'lib/jun/action_dispatch/routing/route_set.rb', line 8

def method
  @method
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



8
9
10
# File 'lib/jun/action_dispatch/routing/route_set.rb', line 8

def name
  @name
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



8
9
10
# File 'lib/jun/action_dispatch/routing/route_set.rb', line 8

def path
  @path
end

Instance Method Details

#controller_classObject



21
22
23
24
# File 'lib/jun/action_dispatch/routing/route_set.rb', line 21

def controller_class
  class_name = "#{controller.camelize}Controller"
  Object.const_get(class_name)
end

#dispatch(request) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/jun/action_dispatch/routing/route_set.rb', line 13

def dispatch(request)
  controller = controller_class.new
  controller.request = request
  controller.response = Rack::Response.new
  controller.handle_response(action)
  controller.response.finish
end

#match?(request) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/jun/action_dispatch/routing/route_set.rb', line 9

def match?(request)
  request.request_method == method && path_regex.match?(request.path_info)
end

#path_regexObject



26
27
28
29
# File 'lib/jun/action_dispatch/routing/route_set.rb', line 26

def path_regex
  path_string_for_regex = path.gsub(/:\w+/) { |match| "(?<#{match.delete(":")}>\\w+)" }
  Regexp.new("^#{path_string_for_regex}\/?$")
end