Skip to content

Use name_plural and display_name_plural#861

Merged
faustinoaq merged 16 commits into
masterfrom
fa/use-pluralize-method
Jun 21, 2018
Merged

Use name_plural and display_name_plural#861
faustinoaq merged 16 commits into
masterfrom
fa/use-pluralize-method

Conversation

@faustinoaq

@faustinoaq faustinoaq commented Jun 16, 2018

Copy link
Copy Markdown
Contributor

Description of the Change

This PR simplifies pluralization by using pluralize method @name_plural variable instead of Inflector.pluralize

Alternate Designs

Keep Inflector.pluralize

Benefits

Less verbose and fixes #713

Possible Drawbacks

No

@faustinoaq faustinoaq requested review from a team and drujensen June 16, 2018 17:35
@faustinoaq faustinoaq requested a review from a team June 16, 2018 18:43

@eliasjpr eliasjpr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not just create a variable called name_plural since its the only variable that gets pluralized? Then everywhere where pluralize(@name) gets replaced with name_plural

@faustinoaq

Copy link
Copy Markdown
Contributor Author

Why not just create a variable called name_plural since its the only variable that gets pluralized?

@eliasjpr Nice idea 👍

@faustinoaq

Copy link
Copy Markdown
Contributor Author

@eliasjpr Done! 🎉

@faustinoaq faustinoaq changed the title Use pluralize method Use @name_plural method Jun 16, 2018
@faustinoaq faustinoaq changed the title Use @name_plural method Use @name_plural variable Jun 16, 2018

response.status_code.should eq(200)
response.body.should contain("<%= Inflector.pluralize(display_name) %>")
response.body.should contain("<%= pluralize(display_name) %>")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

missed one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you, Done! 👍

Comment thread src/amber/cli/recipes/recipe.cr Outdated
exit 1
end

@name_plural = Inflector.pluralize(word)

@marksiemers marksiemers Jun 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where does word come from? Isn't this pluralizing @name?

Also, any reason not to create a getter, or write a custom one like this:

def plural_name
  @plural_name ||= Inflector.pluralize(@name)
end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @marksiemers 🎉

You're completely right, let me fix that 💯

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also, any reason not to create a getter, or write a custom one like this:

Is a getter really needed? I think initialize method already does the job, no?

@name_plural is initialized just one time inside the constructor, so no memoization requirement

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It can be done without the getter, assuming it will never be needed publicly.

If it will ever be needed publicly, then creating a private getter now will make things more consistent when that change comes.

I know this isn't ruby, but one of the ruby idioms that I follow is that you minimize directly accessing instance variables (ideally only in the constructor/initialize method).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@marksiemers Yeah, nice suggestion 👍

I think we can refactor this in a new PR (@name_plural and others) 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

BTW, nice to see you here again 😄 👍

@marksiemers

Copy link
Copy Markdown
Contributor

@faustinoaq - Thanks. I started a new job, moved, and got into rock climbing - so my OSS time has been very limited.

It looks like the CI is currently failing due to Crystal 0.25.0 incompatibilities - I'm assuming that is a bit of a priority - should this PR just wait for those fixes?

Also for this change, if you switch to a getter method, if anything changes in the implementation of that method, you won't have to change 25 files again.

Of course, if the name of the method changes, then we're still stuck with changing all the files.

@faustinoaq

Copy link
Copy Markdown
Contributor Author

Thanks. I started a new job, moved, and got into rock climbing - so my OSS time has been very limited.

Hehe, nice, no problem 👍

I'm assuming that is a bit of a priority - should this PR just wait for those fixes?

Yeah, almost all current PRs depend on #857 😅

Also for this change, if you switch to a getter method, if anything changes in the implementation of that method, you won't have to change 25 files again.

Yeah, you're right, but I think would be nice to change all other ivars as well in a new PR. This would be a bigger refactor. We're using a lot of ivars in all templates 😅

@faustinoaq

Copy link
Copy Markdown
Contributor Author

@marksiemers I guess I was a bit confused about this change (too many files 😅 )

Your're right, is better to use a getter here, I already added it 👍 Thank you!

@faustinoaq faustinoaq changed the title Use @name_plural variable Use name_plural and display_name_plural Jun 21, 2018
@faustinoaq

Copy link
Copy Markdown
Contributor Author

switch to a getter method

@marksiemers Done 👍

@faustinoaq faustinoaq merged commit 6e45528 into master Jun 21, 2018
@faustinoaq faustinoaq deleted the fa/use-pluralize-method branch June 21, 2018 00:25
@faustinoaq faustinoaq added this to the Version 0.8.0 milestone Jun 21, 2018
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.

Refactor Inflector.pluralize

4 participants