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 RubyFileWriter #222

Merged
merged 12 commits into from
Sep 10, 2024
Merged

Refactor RubyFileWriter #222

merged 12 commits into from
Sep 10, 2024

Conversation

cllns
Copy link
Member

@cllns cllns commented Aug 1, 2024

Addresses #202

Although, I ended up not using slice.source_path. I had an implementation working that just took a Hanami::Slice and used .namespace and .source_path but it proved hard to test. I couldn't figure out how to register a slice into the Test::App.

Instead, the RubyFileWriter takes namespace and base_path, and we do the mapping in Generate::Command.

Happy to change this over if we can figure out a simple way to test that, to simplify the code, but I also feel like it's reasonable that a "File Writer" would require a namespace and a path as separate args, even though they're coupled in our apps.

I also changed the RubyFileWriter implementation so that call takes the file-specific args, instead of no args for call and all of them being passed to the initializer. I implemented this via helper class, as passing around all the variables that need to be passed around proved to make the code very messy.

I want to handle this refactoring before using RubyFileWriter in other generators.

@cllns cllns requested a review from timriley August 1, 2024 20:50
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.

Thanks @cllns! These changes all look good to me 👍🏼

Particularly in support for the adjustment to the #initialize/#call args for the FileWriter. This is much more consistent with how we design classes in general.

I left you a couple of questions, but they're minor, so happy for you to merge when ready.

end
super(name: normalized_name, slice: slice, **opts)
def call(name:, **opts)
name = "#{inflector.singularize(name)}_repo" unless name.end_with?("_repo")
Copy link
Member

Choose a reason for hiding this comment

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

Just checking: by reassigning name here, that new value will still be passed up to the superclass method via the no-args version of super below?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup! Which I wasn't expecting. I wrote it explicitly as super(name: name, **opts), but my Rubocop autocorrect got rid of it since it's equivalent to super.

normalized_name = inflector.underscore(name)
ensure_valid_name(normalized_name)
def call(namespace:, key:, base_path:, **_opts)
_namespace = namespace
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for this extra assignment? It doesn't look like we use _namespace anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, it was to appease Rubocop, but clearly the better move is to just remove the namespace: arg altogether, which is what I just committed.

@cllns cllns merged commit 5044783 into main Sep 10, 2024
6 checks passed
@cllns cllns deleted the refactor-ruby-file-writer branch September 10, 2024 22:27
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.

2 participants