Class: WeaselDiesel

Inherits:
Object
  • Object
show all
Defined in:
lib/wd_sinatra/sinatra_ext.rb

Defined Under Namespace

Classes: RequestHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#handlerObject (readonly)

of RequestHandler



90
91
92
# File 'lib/wd_sinatra/sinatra_ext.rb', line 90

def handler
  @handler
end

Instance Method Details

#implementation(&block) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/wd_sinatra/sinatra_ext.rb', line 92

def implementation(&block)
  if block_given?
    @handler = RequestHandler.new(self, &block)
    @handler.define_singleton_method(:service_dispatch, block)
  end
  @handler
end

#load_sinatra_routeObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/wd_sinatra/sinatra_ext.rb', line 100

def load_sinatra_route
  service     = self
  upcase_verb = service.verb.to_s.upcase
  unless ENV['DONT_PRINT_ROUTES']
    LOGGER.info "Available endpoint: #{self.http_verb.upcase} /#{self.url}" 
  end
  raise "DSL is missing the implementation block" unless self.handler && self.handler.respond_to?(:service_dispatch)

  # 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.handler.dispatch(self)
  end
  
end