Skip to content

Commit 4332cb0

Browse files
author
Jerry Cheung
committed
merge ruby-grape#104 into frontier
2 parents 733db89 + a4a06f8 commit 4332cb0

File tree

3 files changed

+4
-36
lines changed

3 files changed

+4
-36
lines changed

README.markdown

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -124,39 +124,6 @@ class API < Grape::API
124124
end
125125
````
126126

127-
128-
## Working with Entities
129-
130-
A common problem in designing Ruby APIs is that you probably don't want
131-
the exact structure of your data models exposed. ActiveRecord, for
132-
instance, will dump all of its attributes. While you can override
133-
`#as_json` to alter this behavior somewhat, what is really needed is an
134-
intermediary layer between the model and the API. This is where the
135-
`Grape::Entity` class comes in.
136-
137-
```ruby
138-
module Entities
139-
class User < Grape::Entity
140-
expose :first_name, :last_name
141-
expose :email, :if => {:authenticated => true}
142-
expose :name, :id => {:version => 'v1'} # deprecated
143-
end
144-
end
145-
146-
class API < Grape::API
147-
version 'v1', 'v2'
148-
149-
get '/users/:id' do
150-
present User.find(params[:id]),
151-
:with => Entities::User,
152-
:authenticated => env.key?('api.token')
153-
end
154-
end
155-
```
156-
157-
For more information about Entities, view the project's YARD
158-
documentation.
159-
160127
## Raising Errors
161128

162129
You can raise errors explicitly.

lib/grape/api.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def version(*args, &block)
9595
if args.any?
9696
options = args.pop if args.last.is_a? Hash
9797
options ||= {}
98-
options = {:using => :header}.merge!(options)
98+
options = {:using => :path}.merge!(options)
9999
@versions = versions | args
100100
nest(block) do
101101
set(:version, args)
@@ -287,6 +287,7 @@ def post(paths = ['/'], options = {}, &block); route('POST', paths, options, &bl
287287
def put(paths = ['/'], options = {}, &block); route('PUT', paths, options, &block) end
288288
def head(paths = ['/'], options = {}, &block); route('HEAD', paths, options, &block) end
289289
def delete(paths = ['/'], options = {}, &block); route('DELETE', paths, options, &block) end
290+
def options(paths = ['/'], options = {}, &block); route('OPTIONS', paths, options, &block) end
290291

291292
def namespace(space = nil, &block)
292293
if space || block_given?

spec/grape/api_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,13 @@ def app; subject end
257257
"lol"
258258
end
259259

260-
%w(get post put delete).each do |m|
260+
%w(get post put delete options).each do |m|
261261
send(m, '/abc')
262262
last_response.body.should eql 'lol'
263263
end
264264
end
265265

266-
verbs = %w(post get head delete put)
266+
verbs = %w(post get head delete put options)
267267
verbs.each do |verb|
268268
it "should allow and properly constrain a #{verb.upcase} method" do
269269
subject.send(verb, '/example') do

0 commit comments

Comments
 (0)