Sha256: dacfb90813a37b799785a93189a4ff2a7df14a3284f72753bfce4c6489bb4500

Contents?: true

Size: 1.21 KB

Versions: 13

Compression:

Stored size: 1.21 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])
  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]}"
    }
  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

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
grape-0.4.1 spec/support/versioned_helpers.rb
grape-0.4.0 spec/support/versioned_helpers.rb
grape-0.3.2 spec/support/versioned_helpers.rb
grape-0.3.1 spec/support/versioned_helpers.rb
grape-0.3.0 spec/support/versioned_helpers.rb
grape-0.2.1.1 spec/support/versioned_helpers.rb
grape-0.2.6 spec/support/versioned_helpers.rb
grape-0.2.5 spec/support/versioned_helpers.rb
grape-0.2.4 spec/support/versioned_helpers.rb
grape-0.2.3 spec/support/versioned_helpers.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/grape-0.2.2/spec/support/versioned_helpers.rb
grape-0.2.2 spec/support/versioned_helpers.rb
grape-0.2.1 spec/support/versioned_helpers.rb