Module: WSDSLSinatraExtension

Defined in:
lib/framework_ext/sinatra.rb

Overview

Module used to extend WSDSL and add #load_sinatra_route to services. This code is Sinatra specific and therefore lives outside the WSDSL

See Also:

  • {WSDSL}

Instance Method Summary collapse

Instance Method Details

#load_sinatra_routeNil

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.

Defines a sinatra service route based on its settings

Returns:

  • (Nil)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/framework_ext/sinatra.rb', line 11

def load_sinatra_route
  service     = self
  upcase_verb = service.verb.to_s.upcase
  puts "/#{self.url} -> #{self.controller_name}##{self.action} - (#{upcase_verb})"

  # Define the route directly to save some object allocations on the critical path
  # Note that we are using a private API to define the route and that unlike sinatra usual DSL
  # we do NOT define a HEAD route for every GET route.
  Sinatra::Base.send(:route, upcase_verb, "/#{self.url}") do
    service.controller_dispatch(self)
  end

  # Other alternative to the route definition, this time using the public API
  # self.send(verb, "/#{service.url}") do
  #   service.controller_dispatch(self)
  # end

end