Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect deprecations #1357

Merged
merged 1 commit into from
Apr 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
0.16.2 (Next)
============

#### Features

* [#1348](https://github.com/ruby-grape/grape/pull/1348): Fix global functions polluting Grape::API scope - [@dblock](https://github.com/dblock).
* [#1357](https://github.com/ruby-grape/grape/pull/1357): Expose Route#options - [@namusyaka](https://github.com/namusyaka).
* Your contribution here.

#### Fixes

* [#1357](https://github.com/ruby-grape/grape/pull/1357): Don't include fixed named captures as route params - [@namusyaka](https://github.com/namusyaka).

0.16.1 (4/3/2016)
=================

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2567,6 +2567,11 @@ Note that `Route#route_xyz` methods have been deprecated since 0.15.0.

Please use `Route#xyz` instead.

Note that difference of `Route#options` and `Route#settings`.

The `options` can be referred from your route, it should be set by specifing key and value on verb methods such as `get`, `post` and `put`.
The `settings` can also be referred from your route, but it should be set by specifing key and value on `route_setting`.

## Current Route and Endpoint

It's possible to retrieve the information about the current route from within an API call with `route`.
Expand Down
8 changes: 4 additions & 4 deletions lib/grape/router/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ class Router
class Route
ROUTE_ATTRIBUTE_REGEXP = /route_([_a-zA-Z]\w*)/.freeze
SOURCE_LOCATION_REGEXP = /^(.*?):(\d+?)(?::in `.+?')?$/.freeze
FIXED_NAMED_CAPTURES = %w(format version).freeze

attr_accessor :pattern, :translator, :app, :index, :regexp
attr_accessor :pattern, :translator, :app, :index, :regexp, :options

alias_method :attributes, :translator

Expand Down Expand Up @@ -78,10 +79,9 @@ def match?(input)

def params(input = nil)
if input.nil?
default = pattern.named_captures.keys.each_with_object({}) do |key, defaults|
defaults[key] = ''
pattern.named_captures.keys.each_with_object(translator.params) do |(key), defaults|
defaults[key] ||= '' unless FIXED_NAMED_CAPTURES.include?(key) || defaults.key?(key)
end
default.delete_if { |key, _| key == 'format' }.merge(translator.params)
else
parsed = pattern.params(input)
parsed ? parsed.delete_if { |_, value| value.nil? }.symbolize_keys : {}
Expand Down
8 changes: 8 additions & 0 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2256,6 +2256,14 @@ def static
expect(route.description).to eq('first method')
expect(route.route_foo).to be_nil
expect(route.params).to eq({})
expect(route.options).to be_a_kind_of(Hash)
end
it 'has params which does not include format and version as named captures' do
subject.version :v1, using: :path
subject.get :first do; end
param_keys = subject.routes.first.params.keys
expect(param_keys).not_to include('format')
expect(param_keys).not_to include('version')
end
it 'describes methods separately' do
subject.desc 'first method'
Expand Down