Skip to content

add back message key in order to have error_codes#1366

Merged
dblock merged 2 commits into
ruby-grape:masterfrom
mkou:message_key
Apr 22, 2016
Merged

add back message key in order to have error_codes#1366
dblock merged 2 commits into
ruby-grape:masterfrom
mkou:message_key

Conversation

@mkou

@mkou mkou commented Apr 19, 2016

Copy link
Copy Markdown
Contributor

In my situation, in the exception validations, I need message keys as well as the translations in order to pass error codes

@dblock

dblock commented Apr 20, 2016

Copy link
Copy Markdown
Member

This needs tests and a CHANGELOG entry, please.

@mkou

mkou commented Apr 20, 2016

Copy link
Copy Markdown
Contributor Author

@dblock Done. Thanks for the feedback

@params = args[:params]
@message_key = args[:message] if args.key?(:message) && args[:message].is_a?(Symbol)
args[:message] = translate_message(args[:message]) if args.key? :message
super

@dblock dblock Apr 21, 2016

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I nitpick? Is this better? Avoids checking key? twice.

return unless args.key?(:message)
@message_key = args[:message] if args[:message].is_a?(Symbol)
args[:message] = translate_message(args[:message])

or with an if, I don't care.

@mkou mkou Apr 21, 2016

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm wouldn't the return bypass the super method?
I like the idea of not checking the key twice though.

@mkou mkou Apr 21, 2016

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you prefer that version ?

super && return unless args.key?(:message)
@message_key = args[:message] if args[:message].is_a?(Symbol)
args[:message] = translate_message(args[:message])
super

or

if args.key?(:message)
  @message_key = args[:message] if args[:message].is_a?(Symbol)
  args[:message] = translate_message(args[:message])
end
super

(I think I prefer the last one)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely the latter 👍

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise I'm with @ridiculous

@mkou

mkou commented Apr 22, 2016

Copy link
Copy Markdown
Contributor Author

Thanks! 😄 What do you think?

@dblock dblock merged commit 59af167 into ruby-grape:master Apr 22, 2016
@dblock

dblock commented Apr 22, 2016

Copy link
Copy Markdown
Member

Merged squashed, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants