Class: Webmate::Routes::Collection
- Inherits:
-
Object
- Object
- Webmate::Routes::Collection
- Defined in:
- lib/webmate/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(&block) ⇒ Object
Call this method to define routes in application Examples: routes = Webmate::Routes::Collection.new routes.define do resources :projects end.
-
#get_routes(method, transport) ⇒ Object
Get routes by method and transport.
-
#initialize ⇒ Collection
constructor
A new instance of Collection.
-
#match(method, transport, path) ⇒ Hash?
Get list of matched routes.
Constructor Details
#initialize ⇒ Collection
Returns a new instance of Collection.
7 8 9 10 11 12 |
# File 'lib/webmate/routes/collection.rb', line 7 def initialize @routes = {} @resource_scope = [] enable_websockets if configatron.websockets.enabled end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
5 6 7 |
# File 'lib/webmate/routes/collection.rb', line 5 def routes @routes end |
Instance Method Details
#define(&block) ⇒ Object
Call this method to define routes in application Examples:
routes = Webmate::Routes::Collection.new
routes.define do
resources :projects
end
20 21 22 |
# File 'lib/webmate/routes/collection.rb', line 20 def define(&block) instance_eval(&block) end |
#get_routes(method, transport) ⇒ Object
Get routes by method and transport
44 45 46 47 |
# File 'lib/webmate/routes/collection.rb', line 44 def get_routes(method, transport) @routes[method] ||= {} @routes[method][transport] || [] end |
#match(method, transport, path) ⇒ Hash?
Get list of matched routes
30 31 32 33 34 35 36 37 |
# File 'lib/webmate/routes/collection.rb', line 30 def match(method, transport, path) get_routes(method, transport.upcase).each do |route| if info = route.match(path) return info end end nil end |