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

Follow DRY principle and remove duplication #21894

Merged
merged 1 commit into from Oct 8, 2015

Conversation

abhishekjain16
Copy link
Contributor

No description provided.

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@sgrif
Copy link
Contributor

sgrif commented Oct 7, 2015

Thanks, but we don't accept cosmetic changes.

@sgrif sgrif closed this Oct 7, 2015
@abhishekjain16
Copy link
Contributor Author

No problem :)

@rafaelfranca rafaelfranca reopened this Oct 7, 2015
@rafaelfranca
Copy link
Member

I think it is worth to merge. I'll review it.

@@ -147,5 +135,9 @@ def optimize_routes_generation? #:nodoc:
def _generate_paths_by_default
true
end

def get_only_path(host)
Copy link
Member

Choose a reason for hiding this comment

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

I think only_path? is better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Dislike get_ prefixes. Rename to only_path_for.

Copy link
Contributor

Choose a reason for hiding this comment

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

Rafaels suggestion was clearer 👍

@rafaelfranca rafaelfranca assigned rafaelfranca and unassigned sgrif Oct 7, 2015
@@ -147,5 +135,9 @@ def optimize_routes_generation? #:nodoc:
def _generate_paths_by_default
true
end

def get_only_path(host)
host.nil? ? _generate_paths_by_default : false
Copy link
Contributor

Choose a reason for hiding this comment

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

Could save the method call and do host ? false : _generate_paths_by_default.

Copy link
Member

Choose a reason for hiding this comment

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

I think if host is false we don't want to return false

Copy link
Member

Choose a reason for hiding this comment

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

@abhishekjain16 this is something you should check first though. Change to @kaspth's suggestion and see if any test fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rafaelfranca @kaspth Great.
I will change method name and will be checking for return value.

@@ -147,5 +135,9 @@ def optimize_routes_generation? #:nodoc:
def _generate_paths_by_default
true
end

def only_path_for(host)
Copy link
Contributor

Choose a reason for hiding this comment

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

I still think only_path? is better 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kaspth Though this method name seems good considering it returns boolean value for now, but what if in future _generate_paths_by_default returns some other value rather than boolean?
Should we still go with only_path?
What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

if that happen we rename the method again. For now let's use only_path?

@abhishekjain16
Copy link
Contributor Author

@rafaelfranca Done 👍

options[:only_path] = false
end
end
options[:only_path] = only_path?(options[:host]) unless options.key?(:only_path)
Copy link
Member

Choose a reason for hiding this comment

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

It is still missing the change of unless in the beginning of the line

@abhishekjain16
Copy link
Contributor Author

@rafaelfranca Sorry. My bad. Change done now 👍

rafaelfranca added a commit that referenced this pull request Oct 8, 2015
Follow DRY principle and remove duplication
@rafaelfranca rafaelfranca merged commit a7bd1c7 into rails:master Oct 8, 2015
@abhishekjain16 abhishekjain16 deleted the refactor_with_dry branch February 13, 2016 05:33
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

5 participants