Sha256: 42bee76d8afae39252509b86d8bafa6cdec9dbd9986d67d4ce081a7f34540e40

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

# Versioning

# 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
    fail 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]}"
    }
  else
    fail 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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
grape-0.16.2 spec/support/versioned_helpers.rb
grape-0.16.1 spec/support/versioned_helpers.rb
grape-0.15.0 spec/support/versioned_helpers.rb
grape-0.14.0 spec/support/versioned_helpers.rb