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

RDART-1010: Allow configuration of generator per realm model class #1641

Merged
merged 8 commits into from Apr 19, 2024

Conversation

nielsenko
Copy link
Contributor

@nielsenko nielsenko commented Apr 18, 2024

Support per realm model configuration of the generator via the GeneratorConfig class. Currently we only support specifying the constructor style to use, as this has been a very frequent request (see #292).

// somewhere define your preferred generator configuration and a const RealmModel that uses it
const config = GeneratorConfig(ctorStyle: CtorStyle.allNamed);
const realmModel = RealmModel.using(generatorConfig: config);

@realmModel // <-- use here
class _Person {
  late String name;
  int age = 42;
}

will generate a constructor like:

Person({
  required String name,
  int age = 42,
}) { ... }

Fixes: #292
Fixes: #1642

Copy link

coveralls-official bot commented Apr 18, 2024

Pull Request Test Coverage Report for Build 8738189165

Details

  • 27 of 29 (93.1%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.05%) to 86.448%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/realm_generator/lib/src/realm_model_info.dart 22 24 91.67%
Totals Coverage Status
Change from base Build 8735259797: 0.05%
Covered Lines: 5894
Relevant Lines: 6818

💛 - Coveralls

This can be used to configure the style of constructor
to use when generating realm object classes.

A new RealmModel.using ctor allows the user to pass
an GeneratorConfig instance when annotating a class.
@nielsenko nielsenko marked this pull request as ready for review April 18, 2024 12:13
Comment on lines +88 to +93
String get plural => switch (this) {
RealmCollectionType.list => 'lists',
RealmCollectionType.set => 'sets',
RealmCollectionType.map => 'maps',
_ => 'none'
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A small drive by edit. Not related to this PR

@@ -13,15 +13,15 @@ class WithPrivateFields extends _WithPrivateFields

WithPrivateFields(
String _plain, {
int _withDefault = 0,
int withDefault = 0,
Copy link
Contributor Author

@nielsenko nielsenko Apr 18, 2024

Choose a reason for hiding this comment

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

This is actually fixing a bug in version 2.1.0. Named arguments cannot start with underscore.

Comment on lines +13 to +16
Person({
required String name,
int age = 42,
}) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The interesting bit

Comment on lines +60 to +61
/// The base type of the generated object class
final ObjectType baseType;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you okay with this?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's a big deal. I don't imagine anyone has any code that reads this value.

@nielsenko nielsenko changed the title Allow configuration of generator per realm model class RDART-1010: Allow configuration of generator per realm model class Apr 18, 2024
Co-authored-by: Nikola Irinchev <irinchev@me.com>
@nielsenko nielsenko merged commit d2c35b8 into main Apr 19, 2024
55 of 56 checks passed
@nielsenko nielsenko deleted the kn/opt-in-named-params branch April 19, 2024 08:57
@Dararii
Copy link

Dararii commented Apr 23, 2024

Can someone tell me how to implement this in Real: 2.1.0?

These lines are resulting in references not found:
const config = GeneratorConfig(ctorStyle: CtorStyle.allNamed);
const realmModel = RealmModel.using(generatorConfig: config);

What class should I import?

@nielsenko
Copy link
Contributor Author

This feature is not released yet. It will go out with the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants