Skip to content
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
merged 2 commits into from Apr 21, 2016

Conversation

jonathan-wheeler
Copy link
Contributor

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

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
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling d498f39 on jonathan-wheeler:pass-symbols-to-model-helpers into cfb90f5 on joost:master.

@jonathan-wheeler
Copy link
Contributor Author

Needed to the ability to use other attributes as the country_code value. eg.

phony_normalize :home_phone, country_code: :home_phone_country
phony_normalize :mobile_phone, country_code: :mobile_phone_country

If it might be useful elsewhere then I'm happy to sort out those rubocop issues and make another changes.

@joost
Copy link
Owner

joost commented Apr 19, 2016

Fails some rubocop checks.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling f9449c0 on jonathan-wheeler:pass-symbols-to-model-helpers into cfb90f5 on joost:master.

@joost joost merged commit acc57a1 into joost:master Apr 21, 2016
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants