Skip to content

expose and format_with DSL broken when receiving blocks? #12

@holden-caulfield

Description

@holden-caulfield

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 end

Trying 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions