Skip to content

Commit 0c6815e

Browse files
committed
add factory methods for EType and descendents
The older pattern of making embeddable companion objects into `ETypes` (e.g., `case class Email extends EType[Email]`) still works, but now you can just mention the `EType` directly, when building your subdomain. (E.g., `Subdomain(???, ???, ETypePool(EType[Email]))`).
1 parent 009918c commit 0c6815e

File tree

89 files changed

+245
-381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+245
-381
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
# Longevity Change Log
1+
# Longevity Changelog
22

3-
## [0.11-SNAPSHOT]
3+
## [0.11.0] - 2016.08.29 - API Simplifications
44

5+
- 2016.08.29 - Add factory methods for `EType` and all its
6+
descendents. The older pattern of making embeddable companion
7+
objects into `ETypes` (e.g., `case class Email extends
8+
EType[Email]`) still works, but now you can just mention the `EType`
9+
directly, when building your subdomain. (E.g., `Subdomain(???, ???,
10+
ETypePool(EType[Email]))`).
511
- 2016.08.28 - Get rid of `DerivedType.polyType` and
612
`DerivedPType.polyPType`. `DerivedType` and `DerivedPType` are now
713
abstract classes instead of traits, so users may need to reorder

src/main/scala/longevity/subdomain/embeddable/DerivedType.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@ import emblem.TypeKey
55
/** one of the derived types in a family of domain entity types. mix this in to
66
* your [[EType]] when it represents a concrete subtype of a [[PolyType]].
77
*/
8-
abstract class DerivedType[P <: Embeddable : TypeKey, Poly >: P <: Embeddable : TypeKey] extends EType[P] {
8+
abstract class DerivedType[E <: Embeddable : TypeKey, Poly >: E <: Embeddable : TypeKey] extends EType[E] {
99

1010
private[longevity] val polyTypeKey: TypeKey[Poly] = implicitly[TypeKey[Poly]]
1111

1212
}
13+
14+
/** contains a factory method for creating `DerivedTypes` */
15+
object DerivedType {
16+
17+
/** create and return an `DerivedType` for types `E` and `Poly` */
18+
def apply[E <: Embeddable : TypeKey, Poly >: E <: Embeddable : TypeKey] = new DerivedType[E, Poly] {
19+
}
20+
21+
}

src/main/scala/longevity/subdomain/embeddable/EType.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@ abstract class EType[E <: Embeddable : TypeKey] {
1212
val eTypeKey: TypeKey[E] = typeKey[E]
1313

1414
}
15+
16+
/** contains a factory method for creating `ETypes` */
17+
object EType {
18+
19+
/** create and return an `EType` for type `E` */
20+
def apply[E <: Embeddable : TypeKey] = new EType[E] {
21+
}
22+
23+
}

src/main/scala/longevity/subdomain/embeddable/EntityType.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@ import emblem.TypeKey
44

55
/** a type class for a [[Entity domain entity]] */
66
abstract class EntityType[E <: Entity : TypeKey] extends EType[E]
7+
8+
/** contains a factory method for creating `EntityTypes` */
9+
object EntityType {
10+
11+
/** create and return an `EntityType` for type `E` */
12+
def apply[E <: Entity : TypeKey] = new EntityType[E] {
13+
}
14+
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
package longevity.subdomain.embeddable
22

3+
import emblem.TypeKey
4+
35
/** the base type for a family of domain entity types. mix this in to your
46
* [[EType]] when it represents an abstract embeddable type with concrete
57
* subtypes.
68
*/
79
trait PolyType[Poly <: Embeddable] extends EType[Poly]
10+
11+
/** contains a factory method for creating `PolyTypes` */
12+
object PolyType {
13+
14+
/** create and return an `PolyType` for type `Poly` */
15+
def apply[Poly <: Embeddable : TypeKey] = new PolyType[Poly] {
16+
}
17+
18+
}

src/main/scala/longevity/subdomain/embeddable/ValueType.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@ import emblem.TypeKey
44

55
/** a value type. functionally equivalent to an [[EntityType]] */
66
abstract class ValueType[A <: ValueObject : TypeKey] extends EType[A]
7+
8+
/** contains a factory method for creating `ValueTypes` */
9+
object ValueType {
10+
11+
/** create and return an `ValueType` for type `A` */
12+
def apply[A <: ValueObject : TypeKey] = new ValueType[A] {
13+
}
14+
15+
}
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package longevity.integration.subdomain.complexConstraint
22

33
import longevity.subdomain.embeddable.ValueObject
4-
import longevity.subdomain.embeddable.ValueType
54

65
case class Email(email: String) extends ValueObject {
76
if (!email.contains('@')) throw new ConstraintValidationException("no '@' in email")
87
}
9-
10-
object Email extends ValueType[Email]

src/test/scala/longevity/integration/subdomain/complexConstraint/package.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package longevity.integration.subdomain
22

3-
import emblem.emblematic.traversors.sync.CustomGeneratorPool
43
import emblem.emblematic.traversors.sync.CustomGenerator
4+
import emblem.emblematic.traversors.sync.CustomGeneratorPool
55
import longevity.context.Cassandra
66
import longevity.context.LongevityContext
77
import longevity.context.Mongo
88
import longevity.subdomain.Subdomain
99
import longevity.subdomain.embeddable.ETypePool
10+
import longevity.subdomain.embeddable.ValueType
1011
import longevity.subdomain.ptype.PTypePool
1112

1213
/** covers a root entity with a simple shorthand constraint */
@@ -15,7 +16,7 @@ package object complexConstraint {
1516
val subdomain = Subdomain(
1617
"Complex Constraint",
1718
PTypePool(ComplexConstraint),
18-
ETypePool(Email))
19+
ETypePool(ValueType[Email]))
1920

2021
val emailGenerator = CustomGenerator.simpleGenerator[Email] { generator =>
2122
Email(s"{generator.generate[String]}@{generate.generate[String]")
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package longevity.integration.subdomain.component
22

33
import longevity.subdomain.embeddable.Entity
4-
import longevity.subdomain.embeddable.EntityType
54

65
case class Component(id: String, tag: String) extends Entity
7-
8-
object Component extends EntityType[Component]

src/test/scala/longevity/integration/subdomain/component/package.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import longevity.context.Cassandra
44
import longevity.context.LongevityContext
55
import longevity.context.Mongo
66
import longevity.subdomain.embeddable.ETypePool
7+
import longevity.subdomain.embeddable.EntityType
78
import longevity.subdomain.Subdomain
89
import longevity.subdomain.ptype.PTypePool
910

1011
/** covers a root entity with a single component entity */
1112
package object component {
1213

13-
val subdomain = Subdomain("Component", PTypePool(WithComponent), ETypePool(Component))
14+
val subdomain = Subdomain("Component", PTypePool(WithComponent), ETypePool(EntityType[Component]))
1415
val mongoContext = LongevityContext(subdomain, Mongo)
1516
val cassandraContext = LongevityContext(subdomain, Cassandra)
1617

0 commit comments

Comments
 (0)