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
refactor reset_primary_key and change !blank? to present? in get_primary... #8800
Conversation
| @@ -68,15 +68,15 @@ def quoted_primary_key | |||
| end | |||
|
|
|||
| def reset_primary_key #:nodoc: | |||
| if self == base_class | |||
| self.primary_key = get_primary_key(base_class.name) | |||
| self.primary_key = if self == base_class | |||
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.
Ugh. I understand the want to get rid of duplication, but I think I'm
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.
@steveklabnik thanks for review, in this case i think that the readably of the code is a little better.
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 disagree. I've always found attribute = if condition statements to be less readable at a glance. I think this is less readable.
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 agree with @steveklabnik
Although this removes the duplication but makes it harder to read
And also when there are more things to add on a specific condition
The form before this refactor is easier to change
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.
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 like attribute= if, in this case we have just less 5 line of code with a very simple logic, anyway my refactoring was focused on the get_primary_key method, @guilleiguaran what do you think about? let' me if I have to rollback reset_primary_keyfor merging. Thanks in advance
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.
Agree with @jeremy here - this is a subjective change and I don't think it's worth polluting the git history for it. The simplification of get_primary_key is is marginally worthwhile so if you update the PR as I suggested below and remove this change I think we can merge it.
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.
How about a ternary?
self.primary_key = self == base_class ? get_primary_key(base_class.name) : base_class.primary_keyI see the point about not polluting the git history, though, as it has no real world benefit. ;)
|
cc / @pixeltrix |
| end | ||
| end | ||
|
|
||
| def get_primary_key(base_name) #:nodoc: | ||
| return 'id' unless base_name && !base_name.blank? | ||
| return 'id' unless base_name.present? |
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.
Couldn't this be return 'id' if base_name.blank? since both nil and "" return true for blank?
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.
@pixeltrix +1
|
@pixeltrix done, thanks for your detailed review |
refactor reset_primary_key and change !blank? to present? in get_primary...
..._key