Skip to content

Commit d3f0c29

Browse files
AMar4enkodblock
authored andcommitted
Routing methods dsl refactored to get rid of explicit paths parameter
Fixes #791
1 parent 0df3bda commit d3f0c29

File tree

2 files changed

+7
-26
lines changed

2 files changed

+7
-26
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* [#819](https://github.com/intridea/grape/pull/819): Allowed both `desc` and `description` in the params DSL - [@mzikherman](https://github.com/mzikherman).
1616
* [#821](https://github.com/intridea/grape/pull/821): Fixed passing string value when hash is expected in params - [@rebelact](https://github.com/rebelact).
1717
* [#824](https://github.com/intridea/grape/pull/824): Validate array params against list of acceptable values - [@dnd](https://github.com/dnd).
18+
* [#813](https://github.com/intridea/grape/pull/813): Routing methods dsl refactored to get rid of explicit `paths` parameter - [@AlexYankee](https://github.com/AlexYankee).
1819
* Your contribution here.
1920

2021
0.9.0 (8/27/2014)

lib/grape/dsl/routing.rb

+6-26
Original file line numberDiff line numberDiff line change
@@ -115,32 +115,12 @@ def route(methods, paths = ['/'], route_options = {}, &block)
115115
reset_validations!
116116
end
117117

118-
def get(paths = ['/'], options = {}, &block)
119-
route('GET', paths, options, &block)
120-
end
121-
122-
def post(paths = ['/'], options = {}, &block)
123-
route('POST', paths, options, &block)
124-
end
125-
126-
def put(paths = ['/'], options = {}, &block)
127-
route('PUT', paths, options, &block)
128-
end
129-
130-
def head(paths = ['/'], options = {}, &block)
131-
route('HEAD', paths, options, &block)
132-
end
133-
134-
def delete(paths = ['/'], options = {}, &block)
135-
route('DELETE', paths, options, &block)
136-
end
137-
138-
def options(paths = ['/'], options = {}, &block)
139-
route('OPTIONS', paths, options, &block)
140-
end
141-
142-
def patch(paths = ['/'], options = {}, &block)
143-
route('PATCH', paths, options, &block)
118+
%w"get post put head delete options patch".each do |meth|
119+
define_method meth do |*args, &block|
120+
options = args.extract_options!
121+
paths = args.first || ['/']
122+
route(meth.upcase, paths, options, &block)
123+
end
144124
end
145125

146126
def namespace(space = nil, options = {}, &block)

0 commit comments

Comments
 (0)