Sha256: 75b68fc480533e3058944821fe2f82a4b0f9127cd7dab7d08e64c97ba5b70aea

Contents?: true

Size: 793 Bytes

Versions: 5

Compression:

Stored size: 793 Bytes

Contents

# frozen_string_literal: true

module Grape
  class Router
    class BaseRoute
      delegate_missing_to :@options

      attr_reader :index, :pattern, :options

      def initialize(**options)
        @options = ActiveSupport::OrderedOptions.new.update(options)
      end

      alias attributes options

      def regexp_capture_index
        CaptureIndexCache[index]
      end

      def pattern_regexp
        pattern.to_regexp
      end

      def to_regexp(index)
        @index = index
        Regexp.new("(?<#{regexp_capture_index}>#{pattern_regexp})")
      end

      class CaptureIndexCache < Grape::Util::Cache
        def initialize
          super
          @cache = Hash.new do |h, index|
            h[index] = "_#{index}"
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
grape-2.2.0 lib/grape/router/base_route.rb
grape-2.1.3 lib/grape/router/base_route.rb
grape-2.1.2 lib/grape/router/base_route.rb
grape-2.1.1 lib/grape/router/base_route.rb
grape-2.1.0 lib/grape/router/base_route.rb