Class: Webmate::RoutesCollection
- Inherits:
-
Object
- Object
- Webmate::RoutesCollection
- Defined in:
- lib/webmate/route_helpers/routes_collection.rb
Constant Summary collapse
- TRANSPORTS =
[:ws, :http]
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #define_routes(&block) ⇒ Object
- #get_routes(method, transport) ⇒ Object
-
#initialize ⇒ RoutesCollection
constructor
A new instance of RoutesCollection.
-
#match(method, transport, path) ⇒ Object
get info about matched route method - GET/POST/PUT/PATCH/DELETE transport - HTTP / WS [ HTTPS / WSS ] path - /projects/123/tasks.
Constructor Details
#initialize ⇒ RoutesCollection
Returns a new instance of RoutesCollection.
7 8 9 10 11 12 |
# File 'lib/webmate/route_helpers/routes_collection.rb', line 7 def initialize @routes = {} @resource_scope = [] enable_websockets_support end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
5 6 7 |
# File 'lib/webmate/route_helpers/routes_collection.rb', line 5 def routes @routes end |
Instance Method Details
#define_routes(&block) ⇒ Object
14 15 16 |
# File 'lib/webmate/route_helpers/routes_collection.rb', line 14 def define_routes(&block) instance_eval(&block) end |
#get_routes(method, transport) ⇒ Object
33 34 35 36 |
# File 'lib/webmate/route_helpers/routes_collection.rb', line 33 def get_routes(method, transport) @routes[method] ||= {} @routes[method][transport] || [] end |
#match(method, transport, path) ⇒ Object
get info about matched route
method - GET/POST/PUT/PATCH/DELETE
transport - HTTP / WS [ HTTPS / WSS ]
path - /projects/123/tasks
23 24 25 26 27 28 29 30 31 |
# File 'lib/webmate/route_helpers/routes_collection.rb', line 23 def match(method, transport, path) routes = get_routes(method, transport) routes.each do |route| if info = route.match(path) return info end end nil end |