Support namespaces in model generator #1588
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Fixes #1184
Adds support for generating namespaced models using the model generator.
Description
Previously:
But now it will create
src/models/blog/post.cr
with the classBlog::Post
.Checklist
crystal tool format spec src
./script/setup
./script/test
I've worked on this using the GitHub web IDE so I never compiled/ran the code, but I've tried real hard to make sure everything is in order (even read the source code of teeplate and some avram), so I'm pretty confident this works. If not I'll fix it.
btw I've never heard/used the Crystal language until now, and I hate it. But hopefully I helped. Although the macro feature is impressive.
Note
There's a small edge case - all of
Foo::Bar::Baz
/Foo::BarBaz
/FooBar::Baz
/FooBarBaz
usecreate_foo_bar_baz
for the name of the migration Avram creates, so if you try to create this conflict then the generation will succeed but the migration generation will fail withMigration name must be unique
.I don't think this is fixable without changing Avram, since it expects a camel-cased name and converts it to underscored, so even if we wanted
Blog::Post
to turn intocreate_blog__post
(double underscore to mark namespace) it isn't possible.And I can't check for this conflict easily since I'd have to check all possibilities of adding double-colons between every word. Or I'd have to look in the migrations folder which is easier, but breaks the abstraction.