- Notifications
You must be signed in to change notification settings - Fork 152
Closed
Description
Seems like the DSL for expose and format_with is not working when passing blocks unless you use explicit parenthesis.
To debug this in isolation, I've use the following code snippet:
class Comment include Grape::Entity::DSL attr_accessor :text entity :text end class Post include Grape::Entity::DSL attr_accessor :title, :content, :comments entity :title, :content do format_with :array_counter { |array| array.size } expose :comment_count { |message, options| message.comments.size } expose :comments, :format_with => :array_counter end endTrying to present a "Post" entity with two "Comments" then throws:
syntax error, unexpected '{', expecting keyword_end The error is thrown while interpreting the format_with or expose lines (in this case format_with since it comes first)
If I change the format_with and expose declarations to include explicit parenthesis like this:
format_with (:array_counter) { |array| array.size } expose (:comment_count) { |message, options| message.comments.size }I then get the expected JSON output
{"title":"Post title","content":"Post contents","comment_count":2,"comments":2} Tried it also with explicit creation of the entities subclassing Grape::Entity instead of including Grape::Entity::DSL, same result
Running ruby version: ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-darwin11.4.2] under Mac OS X 10.7.5
Metadata
Metadata
Assignees
Labels
No labels