Class: Mooncell::Router Private
- Inherits:
-
Object
- Object
- Mooncell::Router
- Defined in:
- lib/mooncell/router.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Command Dispatcher
Instance Method Summary collapse
-
#call(connection, params) ⇒ Object
private
Execute to command.
-
#command(name, command) ⇒ Object
private
Add command.
-
#initialize(app) ⇒ Router
constructor
private
Create rotuer instance.
-
#load(code) ⇒ Object
private
Load routes.
Constructor Details
#initialize(app) ⇒ Router
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create rotuer instance
15 16 17 18 |
# File 'lib/mooncell/router.rb', line 15 def initialize(app) @app = app @routes = Concurrent::Hash.new end |
Instance Method Details
#call(connection, params) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Execute to command
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mooncell/router.rb', line 45 def call(connection, params) command_name = params.delete('command') command_class = @routes[command_name] return if command_class.nil? # TODO: Need refactor command = Kernel.const_get(command_class).new(connection) command.call(params) command.respond.send end |
#command(name, command) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Add command
35 36 37 |
# File 'lib/mooncell/router.rb', line 35 def command(name, command) @routes[name] = command end |
#load(code) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load routes
24 25 26 |
# File 'lib/mooncell/router.rb', line 24 def load(code) instance_eval(code) end |