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

Generate repo #200

Merged
merged 88 commits into from
Jul 14, 2024
Merged

Generate repo #200

merged 88 commits into from
Jul 14, 2024

Conversation

cllns
Copy link
Member

@cllns cllns commented Jul 13, 2024

Builds on work done in #199. This is where those refactors pay off: this almost trivial PR to add a repo generator.

I decided to add some logic for pluralization (update:) singularization:
hanami g repo book => BookRepo
hanami g repo books => BookRepo
hanami g repo books_repo => BooksRepo
hanami g repo book_repo => BookRepo

The idea here is that we want to guide people to naming things with our convention, but if they end their name with _repo then we assume they're doing it intentionally and want that exact name, without any singularization.

Closes #189

Copy link
Member

@timriley timriley left a comment

Choose a reason for hiding this comment

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

This all looks great!

If you could take care of switching from pluralised to singularised names, then we can get this in!

normalized_name = if name.end_with?("_repo")
name
else
"#{inflector.pluralize(name)}_repo"
Copy link
Member

Choose a reason for hiding this comment

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

I love the idea of us providing the combination of convenience and guard rails through our arg handling!

Suggested change
"#{inflector.pluralize(name)}_repo"
"#{inflector.singularize(name)}_repo"

Just one adjustment though: repos are actually named singularly, so BookRepo, not BooksRepo.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, duh! Fixed

else
"#{inflector.pluralize(name)}_repo"
end
slice = inflector.underscore(Shellwords.shellescape(slice)) if slice
Copy link
Member

Choose a reason for hiding this comment

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

TBH, I don't think we need to shellescape this slice arg at all. We're checking for the presence of the slice dir via our generators anyway, so that's validation enough for the slice name.

In #201 I removed the shellescaping, and I reckon we could just do the same here too.

@cllns cllns changed the base branch from generate-struct to main July 14, 2024 02:24
@cllns cllns merged commit 20f2407 into main Jul 14, 2024
6 checks passed
@timriley timriley deleted the generate-repo branch July 14, 2024 05:01
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.

generate repo command
2 participants