-
-
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
Ensure the value of default option must be a string when calling I18n.t #1737
Ensure the value of default option must be a string when calling I18n.t #1737
Conversation
863655c
to
e9393c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor changes please in language. Thanks!
lib/grape/exceptions/base.rb
Outdated
end.join(', ') | ||
end | ||
|
||
def translate_attribute(key, **options) | ||
translate("#{BASE_ATTRIBUTES_KEY}.#{key}", default: key, **options) | ||
translate("#{BASE_ATTRIBUTES_KEY}.#{key}", default: key.to_s, **options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I am nitpicking, but feels like we should do this inside translate
, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is generally better. But I'm not sure if there is any need to pass an alternative symbol key as value of :default
in other cases, though, there isn't any example now.
CHANGELOG.md
Outdated
@@ -7,6 +7,7 @@ | |||
#### Fixes | |||
|
|||
* Your contribution here. | |||
* [#1737](https://github.com/ruby-grape/grape/pull/1737): Ensure the value of default option must be a string when calling i18n.t - [@mlzhuyi](https://github.com/mlzhuyi). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes a bug. What's the error that you get without this fix? That's what should be in the changelog, please.
e9393c5
to
bad7bf3
Compare
CHANGELOG.md
Outdated
@@ -7,6 +7,7 @@ | |||
#### Fixes | |||
|
|||
* Your contribution here. | |||
* [#1737](https://github.com/ruby-grape/grape/pull/1737): Fix translating error whe pass symbols as params in custom validations - [@mlzhuyi](https://github.com/mlzhuyi). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: when passing
0924c22
to
b7fc5bf
Compare
It has been changed @dblock |
lib/grape/exceptions/base.rb
Outdated
@@ -71,6 +71,7 @@ def translate_message(key, **options) | |||
end | |||
|
|||
def translate(key, **options) | |||
options[:default] &&= options[:default].to_s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This modifies the caller's options
, which can easily be a frozen hash or whatever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*
and **
in arguments act a different way with common argument.
def common_argument_test(args)
p args.object_id
end
def keyword_argument_test(**args)
p args.object_id
end
args = { a: 1 }
p args.object_id # => 70338004137000
common_argument_test args # => 70338004137000
keyword_argument_test args # => 70338004136780
In there code, args
in keyword_argument_test
is a new hash, create by the method itself.I think we can treat it as a most basic hash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we always declared it the old fashioned way as options = {}
. I worry that this is different version from version, especially reading this SO. Can we just do this the old fashioned way and avoid surprises?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean refactoring out the code, for there here are many **
now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if I wasn't clear. The double splat is fine. I mean this:
options = options.dup
options[:default] &&= options[:default].to_s
We dup arguments everywhere as far as I can see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a really good habit in case of unknown changes.
I have added it :)
b7fc5bf
to
a8058ba
Compare
a8058ba
to
a23ffad
Compare
Thanks, merged. |
#1735