Skip to content

Commit

Permalink
Add test for CtorStyle.allNamed
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Apr 18, 2024
1 parent cbc4be0 commit 498a46a
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/realm_generator/test/good_test_data/all_named_ctor.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:realm_common/realm_common.dart';

part 'all_named_ctor.realm.dart';

const config = GeneratorConfig(ctorStyle: CtorStyle.allNamed);
const realmModel = RealmModel.using(baseType: ObjectType.realmObject, generatorConfig: config);

@realmModel
class _Person {
late String name;
int age = 42;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'all_named_ctor.dart';

// **************************************************************************
// RealmObjectGenerator
// **************************************************************************

// ignore_for_file: type=lint
class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject {
static var _defaultsSet = false;

Person({
required String name,
int age = 42,
}) {
if (!_defaultsSet) {
_defaultsSet = RealmObjectBase.setDefaults<Person>({
'age': 42,
});
}
RealmObjectBase.set(this, 'name', name);
RealmObjectBase.set(this, 'age', age);
}

Person._();

@override
String get name => RealmObjectBase.get<String>(this, 'name') as String;
@override
set name(String value) => RealmObjectBase.set(this, 'name', value);

@override
int get age => RealmObjectBase.get<int>(this, 'age') as int;
@override
set age(int value) => RealmObjectBase.set(this, 'age', value);

@override
Stream<RealmObjectChanges<Person>> get changes =>
RealmObjectBase.getChanges<Person>(this);

@override
Stream<RealmObjectChanges<Person>> changesFor([List<String>? keyPaths]) =>
RealmObjectBase.getChangesFor<Person>(this, keyPaths);

@override
Person freeze() => RealmObjectBase.freezeObject<Person>(this);

EJsonValue toEJson() {
return <String, dynamic>{
'name': name.toEJson(),
'age': age.toEJson(),
};
}

static EJsonValue _toEJson(Person value) => value.toEJson();
static Person _fromEJson(EJsonValue ejson) {
return switch (ejson) {
{
'name': EJsonValue name,
'age': EJsonValue age,
} =>
Person(
name: fromEJson(name),
age: fromEJson(age),
),
_ => raiseInvalidEJson(ejson),
};
}

static final schema = () {
RealmObjectBase.registerFactory(Person._);
register(_toEJson, _fromEJson);
return SchemaObject(ObjectType.realmObject, Person, 'Person', [
SchemaProperty('name', RealmPropertyType.string),
SchemaProperty('age', RealmPropertyType.int),
]);
}();

@override
SchemaObject get objectSchema => RealmObjectBase.getSchema(this) ?? schema;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

part of 'all_named_ctor.dart';

0 comments on commit 498a46a

Please sign in to comment.