Module: Contrast::Framework::Sinatra::Patch::Base

Defined in:
lib/contrast/framework/sinatra/patch/base.rb

Overview

Our patch into the Sinatra::Base Class, allowing for the inventory of the routes called by the application

Class Method Summary collapse

Class Method Details

.instrumentObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/contrast/framework/sinatra/patch/base.rb', line 35

def instrument
  @_instrument ||= begin
    ::Sinatra::Base.class_eval do
      alias_method :cs__patched_sinatra_base_call!, :call!
      # publicly available method for Sinatra::Base things -- unfortunately,
      # getting the routes appear to require a lookup every time
      def call! *args
        Contrast::Framework::Sinatra::Patch::Base.map_route(cs__class, settings, *args)
        cs__patched_sinatra_base_call!(*args)
      end
    end
    true
  end
end

.map_route(clazz, settings, *args) ⇒ Object

Use logic copied from Sinatra::Base#process_route to determine which pattern matches the request being invoked by Sinatra::Base#call!

Parameters:

  • clazz (Class)

    the Class that extends Sinatra::Base in which this route is defined.

  • settings (Object)

    the Sinatra::Base @settings object.

  • args (Array<Object>)

    we rely on the @settings object in Sinatra::Base and the env variable passed in as args.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/contrast/framework/sinatra/patch/base.rb', line 22

def map_route clazz, settings, *args
  context = Contrast::Agent::REQUEST_TRACKER.current
  return unless context

  env = args[0]
  return unless env
  return unless settings

  convert_routes(context, clazz, settings, env)
rescue StandardError
  # Being careful here since we're directly patching something
end