Skip to content

Add Files#create_or_skip for optional files - #481

Merged
timriley merged 1 commit into
mainfrom
skip-existing-files
Nov 26, 2026
Merged

timriley merged 1 commit into
mainfrom
skip-existing-files

Conversation

@timriley

Copy link
Copy Markdown
Member

Add Files#create_or_skip for generating optional files: if the file already exists, this method does not change it and reports it with a new skip verb. With force: true, it overwrites the file, just like #create.

This method is intended for generators creating files that are helpful but not essential, like the test files generated by Hanami RSpec and Hanami Minitest. Their generators run after the main generator has written its files, and they have been using #write, which replaces a user’s existing test files without a warning.

See hanami/hanami-rspec#53.

Add `Files#create_or_skip` for generating optional files: if the file already exists, this method does not change it and reports it with a new `skip` verb. With `force: true`, it overwrites the file, just like `#create`.

This method is intended for generators creating files that are helpful but not essential, like the test files generated by Hanami RSpec and Hanami Minitest. Their generators run _after_ the main generator has written its files, and they have been using `#write`, which replaces a user’s existing test files without a warning.

See hanami/hanami-rspec#53.
fs.create_or_skip("spec/thing_spec.rb", "new content", force: true)

expect(fs.read("spec/thing_spec.rb")).to eq "new content"
expect(stdout.string).to eq " update spec/thing_spec.rb\n"

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.

I guess technically it "replace" or "overwrite" ("updated" is when we add routes to routes.rb). But I guess this is a different change, outside of the scope of this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's a good callout!

@timriley
timriley merged commit ac71445 into main Nov 26, 2026
18 checks passed
@timriley
timriley deleted the skip-existing-files branch November 26, 2026 21:23
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