Sha256: b338205d228a8e53b24ad378fecadf1897300fceb7d770632538d7fded00814c

Contents?: true

Size: 1013 Bytes

Versions: 1

Compression:

Stored size: 1013 Bytes

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 :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 :header
    {
      'HTTP_ACCEPT' => "application/vnd.#{options[:vendor]}-#{options[:version]}+#{options[:format]}"
    }
  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))
  get path, {}, headers
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-0.2.0 spec/support/versioned_helpers.rb