Permalink
Browse files

start with some sample data

  • Loading branch information...
1 parent fcf50b6 commit e0037bb93e1b0be6f8ea2a940c7b07c3c285cbe0 @maxdemarzi committed Jan 6, 2012
Showing with 27 additions and 1 deletion.
  1. +27 −1 neovigator.rb
View
@@ -20,10 +20,35 @@ def link_to(url, text=url, opts={})
end
def neo
- @neo ||= ENV['NEO4J_URL'].nil? ? Neography::Rest.new : Neography::Rest.new(ENV['NEO4J_URL'])
+ @neo = Neography::Rest.new(ENV['NEO4J_URL'] || "http://localhost:7474")
end
end
+ def create_graph
+ graph_exists = neo.get_node_properties(1)
+ return if graph_exists && graph_exists['name']
+
+ johnathan = create_person('Johnathan')
+ mark = create_person('Mark')
+ phil = create_person('Phil')
+ mary = create_person('Mary')
+ luke = create_person('Luke')
+ make_mutual(johnathan, mark, "friends")
+ make_mutual(mark, mary, "friends")
+ make_mutual(mark, phil, "friends")
+ make_mutual(phil, mary, "married")
+ make_mutual(phil, luke, "enemies")
+ end
+
+ def make_mutual(node1, node2, rel_type)
+ neo.create_relationship(rel_type, node1, node2)
+ neo.create_relationship(rel_type, node2, node1)
+ end
+
+ def create_person(name)
+ neo.create_node("name" => name)
+ end
+
def neighbours
{"order" => "depth first",
"uniqueness" => "none",
@@ -90,6 +115,7 @@ def get_properties(node)
end
get '/' do
+ create_graph
@neoid = params["neoid"]
haml :index
end

0 comments on commit e0037bb

Please sign in to comment.