Sha256: aadf60e3bfc36fdc48f6aec6a34fe450a79f502b29930debce9ddf552dda5fa2

Contents?: true

Size: 1.07 KB

Versions: 44

Compression:

Stored size: 1.07 KB

Contents

# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2016

require "instana/rack"

module Instana
  module RodaPathTemplateExtractor
    module RequestMethods
      TERM = defined?(::Roda) ? ::Roda::RodaPlugins::Base::RequestMethods::TERM : Object

      def if_match(args, &blk)
        path = @remaining_path
        captures = @captures.clear

        if match_all(args)
          (env['INSTANA_PATH_TEMPLATE_FRAGMENTS'] ||= []).concat(named_args(args, blk))
          block_result(blk.(*captures))
          env['INSTANA_HTTP_PATH_TEMPLATE'] = env['INSTANA_PATH_TEMPLATE_FRAGMENTS']
            .join('/')
            .prepend('/')
          throw :halt, response.finish
        else
          @remaining_path = path
          false
        end
      end

      def named_args(args, blk)
        parameters = blk.parameters
        args.map do |a|
          case a
          when String
            a
          when TERM
            nil
          else
            _, name = parameters.pop
            "{#{name}}"
          end
        end.reject { |v| v.nil? }
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
instana-1.209.6 lib/instana/frameworks/roda.rb
instana-1.209.5 lib/instana/frameworks/roda.rb
instana-1.209.4 lib/instana/frameworks/roda.rb
instana-1.209.3 lib/instana/frameworks/roda.rb
instana-1.209.2 lib/instana/frameworks/roda.rb
instana-1.209.1 lib/instana/frameworks/roda.rb
instana-1.209.0.pre3 lib/instana/frameworks/roda.rb
instana-1.209.0.pre2 lib/instana/frameworks/roda.rb
instana-1.209.0.pre1 lib/instana/frameworks/roda.rb
instana-1.208.0 lib/instana/frameworks/roda.rb
instana-1.207.0 lib/instana/frameworks/roda.rb
instana-1.206.0 lib/instana/frameworks/roda.rb
instana-1.205.0 lib/instana/frameworks/roda.rb
instana-1.204.0 lib/instana/frameworks/roda.rb
instana-1.204.0.pre3 lib/instana/frameworks/roda.rb
instana-1.204.0.pre2 lib/instana/frameworks/roda.rb
instana-1.204.0.pre1 lib/instana/frameworks/roda.rb
instana-1.203.2 lib/instana/frameworks/roda.rb
instana-1.203.1 lib/instana/frameworks/roda.rb
instana-1.203.0 lib/instana/frameworks/roda.rb