Class: Webmate::Application
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Webmate::Application
- Defined in:
- lib/webmate/application.rb,
lib/webmate.rb
Class Method Summary collapse
- .configure(env = nil, &block) ⇒ Object
- .define_routes(&block) ⇒ Object
- .get_channel_name_for(user_id) ⇒ Object
- .load_tasks ⇒ Object
Instance Method Summary collapse
-
#find_route(routes, request) ⇒ Object
Find matched route by routes collection and request.
-
#route!(base = settings, pass_block = nil) ⇒ Object
override sinatra’s method.
Class Method Details
.configure(env = nil, &block) ⇒ Object
26 27 28 29 30 |
# File 'lib/webmate/application.rb', line 26 def configure(env = nil, &block) if !env || Webmate.env?(env) block.call(configatron) end end |
.define_routes(&block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/webmate/application.rb', line 32 def define_routes(&block) settings = Webmate::Application unless settings.routes.is_a?(Routes::Collection) routes = Routes::Collection.new() settings.set(:routes, routes) end settings.routes.define(&block) routes end |
.get_channel_name_for(user_id) ⇒ Object
43 44 45 |
# File 'lib/webmate/application.rb', line 43 def get_channel_name_for(user_id) channel_name = "some-unique-key-for-app-#{user_id}" end |
.load_tasks ⇒ Object
47 48 49 50 |
# File 'lib/webmate/application.rb', line 47 def load_tasks file_path = Pathname.new(__FILE__) load File.join(file_path.dirname, "../../tasks/routes.rake") end |
Instance Method Details
#find_route(routes, request) ⇒ Object
Find matched route by routes collection and request
20 21 22 23 |
# File 'lib/webmate/application.rb', line 20 def find_route(routes, request) transport = request.websocket? ? 'WS' : 'HTTP' routes.match(request.request_method, transport, request.path) end |
#route!(base = settings, pass_block = nil) ⇒ Object
override sinatra’s method
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/webmate/application.rb', line 4 def route!(base = settings, pass_block = nil) route_info = find_route(base.routes, @request) # no route case - use default sinatra's processors if route_info handler = Webmate::Routes::Handler.new(base, @request) handler.handle(route_info) else route_eval(&pass_block) if pass_block route_missing end end |