Class: Kea::Router
- Inherits:
-
Object
- Object
- Kea::Router
- Defined in:
- lib/kea/router.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize ⇒ Router
constructor
A new instance of Router.
- #render_error(error) ⇒ Object
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
7 8 |
# File 'lib/kea/router.rb', line 7 def initialize end |
Class Method Details
.do_route ⇒ Object
3 4 5 |
# File 'lib/kea/router.rb', line 3 def self.do_route new end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/kea/router.rb', line 10 def call(env) @env = env request = Rack::Request.new(env) body = request.body.read params = JSON.parse(body).deep_symbolize_keys request.body.rewind begin @endpoint = params[:endpoint].classify.constantize unless @endpoint.ancestors.include? Kea::Controller return render_error({endpoint: 'does not descend from Kea::Controller'}) end rescue => e return render_error({exception: e.}) end @endpoint.action(:run_kea_action).call(env) end |
#render_error(error) ⇒ Object
32 33 34 35 |
# File 'lib/kea/router.rb', line 32 def render_error(error) @env['kea.error'] = error Kea::ErrorController.action(:render_kea_error).call(@env) end |