Sha256: c56888bfb8b231ad8f11d0e682b0e16ce75eb8ca951958ce5a489d94903ff1ea

Contents?: true

Size: 1.76 KB

Versions: 15

Compression:

Stored size: 1.76 KB

Contents

# Versioning
module Spec
  module Support
    module Helpers
      # Returns the path with options[:version] prefixed if options[:using] is :path.
      # Returns normal path otherwise.
      def versioned_path(options = {})
        case options[:using]
        when :path
          File.join('/', options[:prefix] || '', options[:version], options[:path])
        when :param
          File.join('/', options[:prefix] || '', options[:path])
        when :header
          File.join('/', options[:prefix] || '', options[:path])
        when :accept_version_header
          File.join('/', options[:prefix] || '', options[:path])
        else
          raise ArgumentError.new("unknown versioning strategy: #{options[:using]}")
        end
      end

      def versioned_headers(options)
        case options[:using]
        when :path
          {}  # no-op
        when :param
          {}  # no-op
        when :header
          {
            'HTTP_ACCEPT' => [
              "application/vnd.#{options[:vendor]}-#{options[:version]}",
              options[:format]
            ].compact.join('+')
          }
        when :accept_version_header
          {
            'HTTP_ACCEPT_VERSION' => options[:version].to_s
          }
        else
          raise ArgumentError.new("unknown versioning strategy: #{options[:using]}")
        end
      end

      def versioned_get(path, version_name, version_options = {})
        path    = versioned_path(version_options.merge(version: version_name, path: path))
        headers = versioned_headers(version_options.merge(version: version_name))
        params = {}
        if version_options[:using] == :param
          params = { version_options[:parameter] => version_name }
        end
        get path, params, headers
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/spec/support/versioned_helpers.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/spec/support/versioned_helpers.rb
grape-1.2.5 spec/support/versioned_helpers.rb
grape-1.2.4 spec/support/versioned_helpers.rb
grape-1.2.3 spec/support/versioned_helpers.rb
grape-1.2.2 spec/support/versioned_helpers.rb
grape-1.2.1 spec/support/versioned_helpers.rb
grape-1.2.0 spec/support/versioned_helpers.rb
grape-1.1.0 spec/support/versioned_helpers.rb
grape-1.0.3 spec/support/versioned_helpers.rb
grape-1.0.2 spec/support/versioned_helpers.rb
grape-1.0.1 spec/support/versioned_helpers.rb
grape-1.0.0 spec/support/versioned_helpers.rb
grape-0.19.2 spec/support/versioned_helpers.rb
grape-0.19.1 spec/support/versioned_helpers.rb