moaxcp / graph-dsl

A groovy dsl for creating and traversing graphs.
https://moaxcp.github.io/graph-dsl/
MIT License
27 stars 6 forks source link

Remove config method from VertexSpec #65

Closed moaxcp closed 7 years ago

moaxcp commented 7 years ago

Creating a vertex is still a pain. It is hard to understand what should go into the config closure and how it relates to what happens outside of the config closure. The vertex closure needs to be streamlined so config traits can be setup and the graph can be setup while the closure is running.

VertexSpec

The config closure will be renamed to runnerCode. It will contain the closure passed to vertex methods.

vertex methods

All methods will create a VertexSpec and pass it to the vertex(VertexSpec) method

vertex(String)
vertex(String, Map)
vertex(String, Map, Closure)
vertex(String, Closure)
vertex(VertexSpec)

VertexSpecRunner in vertex(VertexSpec)

A new object that will run VertexSpec.runnerCode. It will perform all statements in the closure on the graph, and vertex. It will control new methods that are available to the closure.

This is an example of what should be able to happen in the closure.

vertex step1 {
    traits Mapping
    key = 'value'
    traits Weight
    weight 20
}

vertex step2(traits:Mapping) {
    key = 'value'
    traits Weight
    weight 30
    edgesFirst 'step1'
    println adjacentEdges(name)
}

This allows traits to be applied and code to execute against the trait once it is added.