-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Entity Formatters #152
Comments
I like the idea, at least in theory. Implementation wise here would be my suggestion: Rather than declaring formatter methods, let's just have a
This way you can create custom formatters as lambdas, custom classes, or anything in between. You can also just use simple method-based ones like your example above. REVERSER = lambda{|value| value.reverse}
module Entities
class User < Grape::Entity
expose :name
expose :created_at, :format_with => :timestamp
expose :backwards_name, :format_with => REVERSER
private
def timestamp(date)
date.strftime('%m/%d/%Y')
end
end
end |
I'm not 100% sold on |
Yeah I had the same thought on a lambda option as well. Although it would look odd if they supplied a block as well.
I guess the options are:
|
I'd like to get some input on formatters for entities, I have an idea.
The text was updated successfully, but these errors were encountered: