Class: CommunityZero::Router
- Inherits:
-
Object
- Object
- CommunityZero::Router
- Defined in:
- lib/community_zero/router.rb
Overview
The router for the Community Server.
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #call(request) ⇒ Object
-
#initialize(server, *routes) ⇒ Router
constructor
A new instance of Router.
Constructor Details
#initialize(server, *routes) ⇒ Router
Returns a new instance of Router.
25 26 27 28 29 30 31 |
# File 'lib/community_zero/router.rb', line 25 def initialize(server, *routes) @server = server @routes = routes.map do |route, endpoint| pattern = Regexp.new("^#{route.gsub(/:[A-Za-z_]+/, '[^/]*')}$") [pattern, endpoint] end end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
23 24 25 |
# File 'lib/community_zero/router.rb', line 23 def routes @routes end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
23 24 25 |
# File 'lib/community_zero/router.rb', line 23 def server @server end |
Instance Method Details
#call(request) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/community_zero/router.rb', line 33 def call(request) begin path = '/' + request.path.join('/') find_endpoint(path).new(server).call(request) rescue [ 500, { 'Content-Type' => 'text/plain' }, "Exception raised! #{$!.inspect}\n#{$!.backtrace.join("\n")}" ] end end |