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
Adds ability to pass symbols as option values to phony model helpers #139
Merged
joost
merged 2 commits into
joost:master
from
jonathan-wheeler:pass-symbols-to-model-helpers
Apr 21, 2016
Merged
Adds ability to pass symbols as option values to phony model helpers #139
joost
merged 2 commits into
joost:master
from
jonathan-wheeler:pass-symbols-to-model-helpers
Apr 21, 2016
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previously attributes such as country_code had to be strings and could not be set at runtime. It was possible to set a method named country_code on the model but it situations where you might have multiple phone numbers on the same model this was still somewhat limited. Using symbols allows you to use other model attributes to set the country code attributes.For instance the following is now possible Table - Person home_phone mobile_phone home_phone_country mobile_phone_country phony_normalize :home_phone, country_code: :home_phone_country phony_normalize :mobile_phone, country_code: :mobile_phone_country
Needed to the ability to use other attributes as the country_code value. eg.
If it might be useful elsewhere then I'm happy to sort out those rubocop issues and make another changes. |
Fails some rubocop checks. |
monfresh
added a commit
to monfresh/phony_rails
that referenced
this pull request
Apr 28, 2016
**Why**: With the changes in PR joost#139, specifying a symbolized value for the `message` option would cause that method to be called on the Model object. If that method didn't exist, it resulted in a `NoMethodError` exception. If that method did exist in the Model, and also as an i18n key, then the Model method was used, as opposed to the i18n key. The `message` option is meant to either be a String, or a symbol corresponding to an i18n key. Therefore, it should be read directly from `options[:message]` and not sent for further processing by the `options_value` method. **How**: - Revert the `error_message` method back to its value prior to PR joost#139, so that it uses `options[:message]` - Add 3 new specs to cover these scenarios
monfresh
added a commit
to monfresh/phony_rails
that referenced
this pull request
Apr 28, 2016
**Why**: With the changes in PR joost#139, specifying a symbolized value for the `message` option would cause that method to be called on the Model object. If that method didn't exist, it resulted in a `NoMethodError` exception. If that method did exist in the Model, and also as an i18n key, then the Model method was used, as opposed to the i18n key. The `message` option is meant to either be a String, or a symbol corresponding to an i18n key. Therefore, it should be read directly from `options[:message]` and not sent for further processing by the `options_value` method. **How**: - Revert the `error_message` method back to its value prior to PR joost#139, so that it uses `options[:message]` - Add 3 new specs to cover these scenarios
monfresh
added a commit
to monfresh/phony_rails
that referenced
this pull request
Apr 28, 2016
**Why**: With the changes in PR joost#139, specifying a symbolized value for the `message` option would cause that method to be called on the Model object. If that method didn't exist, it resulted in a `NoMethodError` exception. If that method did exist in the Model, and also as an i18n key, then the Model method was used, as opposed to the i18n key. The `message` option is meant to either be a String, or a symbol corresponding to an i18n key. Therefore, it should be read directly from `options[:message]` and not sent for further processing by the `options_value` method. **How**: - Revert the `error_message` method back to its value prior to PR joost#139, so that it uses `options[:message]` - Add 3 new specs to cover these scenarios
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously attributes such as country_code had to be strings and
could not be set at runtime. It was possible to set a method named
country_code on the model but it situations where you might have
multiple phone numbers on the same model this was still somewhat
limited.
Using symbols allows you to use other model attributes to set the
country code attributes.For instance the following is now possible
Table - Person
home_phone
mobile_phone
home_phone_country
mobile_phone_country
phony_normalize :home_phone, country_code: :home_phone_country
phony_normalize :mobile_phone, country_code: :mobile_phone_country