Skip to content

Instantly share code, notes, and snippets.

@hryk
Last active December 13, 2015 22:08
Show Gist options
  • Save hryk/4982309 to your computer and use it in GitHub Desktop.
Save hryk/4982309 to your computer and use it in GitHub Desktop.
Examples for using blueprints on JRuby.

Blueprints on JRuby

Examples for using blueprints on JRuby.

Install gems and jars

$ rbenv shell jruby-1.7.2
$ bundle install
$ jbundle install

Try blueprints

$ rbenv shell jruby-1.7.2
$ ruby blueprints-example.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'jbundler'
import com.tinkerpop.blueprints.impls.tg.TinkerGraph
import com.tinkerpop.blueprints.Graph
import com.tinkerpop.blueprints.Vertex
import com.tinkerpop.blueprints.Edge
import com.tinkerpop.blueprints.Direction
graph = TinkerGraph.new()
node_a = graph.addVertex(nil);
node_b = graph.addVertex(nil);
node_a.setProperty("name", "marko");
node_b.setProperty("name", "peter");
edge = graph.addEdge(nil, node_a, node_b, "knows");
puts "#{edge.getVertex(Direction::OUT).getProperty("name")}--#{edge.getLabel()}-->#{edge.getVertex(Direction::IN).getProperty("name")}"
source "https://rubygems.org/"
gem "neo4j"
gem "pry"
gem "minitest"
gem "jbundler"
#!/usr/bin/env ruby
#
# ## Iterate through the Edges of a Vertex
# https://github.com/tinkerpop/blueprints/wiki/Code-Examples
#
require 'rubygems'
require 'bundler/setup'
require 'jbundler'
import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory
import com.tinkerpop.blueprints.Direction
graph = TinkerGraphFactory.create_tinker_graph()
a = graph.get_vertex("1");
puts "vertex #{a.get_id()} has name #{a.get_property("name")}"
a.get_edges(Direction::OUT).each do |e|
puts e
end
#!/usr/bin/env ruby
#
# ## Iterate through the Elements of a Graph
# https://github.com/tinkerpop/blueprints/wiki/Code-Examples
#
require 'rubygems'
require 'bundler/setup'
require 'jbundler'
import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory
graph = TinkerGraphFactory.create_tinker_graph()
puts "Vertices of #{graph}"
graph.get_vertices.each do |v|
puts v
end
puts "Ediges of #{graph}"
graph.get_edges.each do |e|
puts e
end
# vim: syntax=ruby :
# encoding: utf-8
jar "com.tinkerpop.blueprints:blueprints-neo4j-graph", "2.2.0"
jar "com.tinkerpop.blueprints:blueprints-orient-graph", "2.2.0"
jar "com.tinkerpop:pipes", "2.2.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment