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

refactor reset_primary_key and change !blank? to present? in get_primary... #8800

Merged
merged 1 commit into from Jan 8, 2013

Conversation

acapilleri
Copy link
Contributor

..._key

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

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 👎 on this.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Member

Choose a reason for hiding this comment

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

🚲🏡

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

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_key

I see the point about not polluting the git history, though, as it has no real world benefit. ;)

@acapilleri
Copy link
Contributor Author

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?
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

@acapilleri
Copy link
Contributor Author

@pixeltrix done, thanks for your detailed review

pixeltrix added a commit that referenced this pull request Jan 8, 2013
refactor reset_primary_key and change !blank? to present? in get_primary...
@pixeltrix pixeltrix merged commit de21da5 into rails:master Jan 8, 2013
@acapilleri acapilleri deleted the primary_key branch January 8, 2013 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants