Implement generic component generator
Context:
Hi. I noticed this task in Hanami github projects: https://github.com/orgs/hanami/projects/2?pane=issue&itemId=37953496 Thought I give it a go, to get acquainted with dry-rb and hanami source code more, and maybe be useful to maintainers as a side effect. I know the task was marked as "maybe" but I often wrote generators for rails and wanted to see how much different would it be here.
Solution:
The generator is really simple, as components are general objects with no one interface or anything. It is basically a shortcut to creating a file with the right name in the right scope and slice or no slice. That is what I understood that the idea was behind this task.
I also accounted for CLI receiving the name in Pascal Case like Opeations::CreateUser. This is a personal preference, since this is how I usually generate new ruby classes through rubymine, but I think it might be a useful option for some.
TBD:
For my code, the collection of constants with different characters used in lib/hanami/cli/generators/app/view_context.rb was also useful. I noticed the TODO that it should be moved. I would like to do thath, but I am unsure what would be the desired location. Something like lib/hanami/cli/constants.rb seems to generic. I was thinking more along the lines of lib/hanami/cli/formatting since all those constants are used to format the input or output but it also does not seem right (this naming seems like a stretch, or might be misleading, since it is not functional, it would just be a module with constants or something).
Anyway, eager to see any form of feedback. Would you like the generator to do something more, or just general code feedback.
I was also unsure about how to document the code with the version tags.
Some screenshots of usage of my local gem version:
https://github.com/orgs/hanami/projects/2?pane=issue&itemId=37953496
https://github.com/hanami/cli/issues/145
@timriley I removed private from methods that are already in private scope and changed the version to 2.2.0 on stuff that was added.
Thanks @krzykamil! 😍