Skip to content

Instantly share code, notes, and snippets.

View tjackiw's full-sized avatar

Thiago Jackiw tjackiw

  • San Francisco Bay Area
View GitHub Profile
@tjackiw
tjackiw / gist:4335224
Created December 19, 2012 08:13
Using a Graph Database with Ruby. Part II: Integration
$ gem install 'neo4j'
@tjackiw
tjackiw / gist:4335219
Created December 19, 2012 08:12
Using a Graph Database with Ruby. Part II: Integration
gem 'neo4j'
@tjackiw
tjackiw / gist:4333239
Created December 18, 2012 23:58
Using a Graph Database with Ruby. Part II: Integration
me = User.first
andy = User.last
me.all_friends_to(andy)
=> "Me => Bob => Mark => Mary => John => Andy"
@tjackiw
tjackiw / gist:4333221
Created December 18, 2012 23:55
Using a Graph Database with Ruby. Part II: Integration
def all_friends_to(user)
neo_node.all_simple_paths_to(user.neo_node).incoming(:friends).depth(5).nodes.each do |node|
puts node.map{|n| n.name }.join(' => ')
end
end
@tjackiw
tjackiw / gist:4333121
Created December 18, 2012 23:41
Using a Graph Database with Ruby. Part II: Integration
Friendship.create_both(me, bob)
Friendship.create_both(bob, mark)
Friendship.create_both(mark, mary)
Friendship.create_both(mary, john)
Friendship.create_both(john, andy)
@tjackiw
tjackiw / gist:4333111
Created December 18, 2012 23:40
Using a Graph Database with Ruby. Part II: Integration
me = User.create(name: 'Me', age: 31)
bob = User.create(name: 'Bob', age: 29)
mark = User.create(name: 'Mark', age: 34)
mary = User.create(name: 'Mary', age: 32)
john = User.create(name: 'John', age: 33)
andy = User.create(name: 'Andy', age: 31)
@tjackiw
tjackiw / gist:4332994
Created December 18, 2012 23:14
Using a Graph Database with Ruby. Part II: Integration
$ rake db:migrate
@tjackiw
tjackiw / gist:4332984
Created December 18, 2012 23:12
Using a Graph Database with Ruby. Part II: Integration
require('neography') unless defined?(Neography)
ENV["NEO4J_URL"] ||= "http://localhost:7474"
uri = URI.parse(ENV["NEO4J_URL"])
neo = Neography::Rest.new(uri.to_s)
Neography.configure do |c|
c.server = uri.host
@tjackiw
tjackiw / gist:4332914
Created December 18, 2012 23:01
Using a Graph Database with Ruby. Part II: Integration
class Friendship < ActiveRecord::Base
include Neoid::Relationship
attr_accessible :friend
belongs_to :user
belongs_to :friend, class_name: User
neoidable do |c|
c.relationship start_node: :user, end_node: :friend, type: :friends
@tjackiw
tjackiw / gist:4332843
Created December 18, 2012 22:53
Using a Graph Database with Ruby. Part II: Integration
class User < ActiveRecord::Base
include Neoid::Node
attr_accessible :name, :age
has_many :friends, class_name: Friendship
neoidable do |c|
c.field :name
end