geoff ===== Ruby Geoff DSL Preview ======= ```ruby #Basic tree like structure for DSL #the first line generates the class nodes used by Neo4jWrapper Geoff(Company, Person) do company 'Acme' do address "13 Something Road" children :employees do person 'Geoff' do name 'Geoff' end person 'Nigel' do name 'Nigel Small' end end end company 'Github' do children :customers do person 'Tom' person 'Dick' person 'Harry' end end end ``` ``` (ROOT)-[:Company]->(Company) (ROOT)-[:Person]->(Person) (Acme) {"_classname":"Company","address":"13 Something Road"} (Company)-[:all]->(Acme) (Geoff) {"_classname":"Person","name":"Geoff"} (Person)-[:all]->(Geoff) (Acme)-[:employees]->(Geoff) (Nigel) {"_classname":"Person","name":"Nigel Small"} (Person)-[:all]->(Nigel) (Acme)-[:employees]->(Nigel) (Github) {"_classname":"Company"} (Company)-[:all]->(Github) (Tom) {"_classname":"Person"} (Person)-[:all]->(Tom) (Github)-[:customers]->(Tom) (Dick) {"_classname":"Person"} (Person)-[:all]->(Dick) (Github)-[:customers]->(Dick) (Harry) {"_classname":"Person"} (Person)-[:all]->(Harry) (Github)-[:customers]->(Harry) ``` #Individual relationship overrides ```ruby Geoff(Company, Person) do company 'Amazon' do children do person 'Tom', type: :customers person 'Tom', type: :supplier end end end ``` ``` (ROOT)-[:Company]->(Company) (ROOT)-[:Person]->(Person) (Amazon) {"_classname":"Company"} (Company)-[:all]->(Amazon) (Tom) {"_classname":"Person"} (Person)-[:all]->(Tom) (Amazon)-[:customers]->(Tom) (Tom) {"_classname":"Person"} (Person)-[:all]->(Tom) (Amazon)-[:supplier]->(Tom) ``` #Link arbitrary nodes in different branches of the tree ##Uses the magic 'b' method ```ruby Geoff(Company, Person) do company 'Amazon' do children 'employees' do b.judas = person 'Judas' end end company 'Moonlighters' do children do b.judas type: 'employees' end end end ``` ``` (ROOT)-[:Company]->(Company) (ROOT)-[:Person]->(Person) (Amazon) {"_classname":"Company"} (Company)-[:all]->(Amazon) (Tom) {"_classname":"Person"} (Person)-[:all]->(Tom) (Amazon)-[:employees]->(Tom) (Moonlighters) {"_classname":"Company"} (Company)-[:all]->(Moonlighters) (Moonlighters)-[:employees]->(Tom) ``` #Using the outer bindings scope ```ruby @hours = SomeFancyAttributeParser.parse <<-EOF Monday 09:00-15:00 Tuesday 13:00-19:00 Saturday 09:00-16:00 Sunday closed EOF Geoff(Company, binding: binding) do company 'Amazon' do opening_hours ->{ @hours } end end ```