ruxster 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +20 -0
- data/README.textile +30 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/ruxster/base.rb +62 -0
- data/lib/ruxster/edge.rb +95 -0
- data/lib/ruxster/vertex.rb +57 -0
- data/lib/ruxster.rb +18 -0
- data/ruxster.gemspec +88 -0
- data/spec/base_spec.rb +39 -0
- data/spec/edge_spec.rb +119 -0
- data/spec/ruxster_spec.rb +8 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/vertex_spec.rb +93 -0
- metadata +206 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "json", "~> 1.2.4"
|
7
|
+
gem "excon", "~> 0.3.6"
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "rspec", "~> 2.3.0"
|
13
|
+
gem "bundler", "~> 1.0.0"
|
14
|
+
gem "jeweler", "~> 1.5.2"
|
15
|
+
gem "rcov", ">= 0"
|
16
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Christopher Petersen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
h2. ruxster
|
2
|
+
|
3
|
+
First install Rexster
|
4
|
+
* Checkout from https://github.com/tinkerpop/rexster
|
5
|
+
* Install maven2
|
6
|
+
* Edit src/main/resources/com/tinkerpop/rexster/rexster.xml and add
|
7
|
+
|
8
|
+
bc. <graph>
|
9
|
+
<graph-name>database</graph-name>
|
10
|
+
<graph-type>tinkergraph</graph-type>
|
11
|
+
<packages-allowed>gremlin</packages-allowed>
|
12
|
+
</graph>
|
13
|
+
|
14
|
+
* Run mvn install
|
15
|
+
|
16
|
+
h3. Contributing to ruxster
|
17
|
+
|
18
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
19
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
20
|
+
* Fork the project
|
21
|
+
* Start a feature/bugfix branch
|
22
|
+
* Commit and push until you are happy with your contribution
|
23
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
24
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
25
|
+
|
26
|
+
h3. Copyright
|
27
|
+
|
28
|
+
Copyright (c) 2010 Christopher Petersen. See LICENSE.txt for
|
29
|
+
further details.
|
30
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "ruxster"
|
16
|
+
gem.homepage = "http://github.com/cpetersen/ruxster"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{An Object Graph Mapper (OGM) for Rexster}
|
19
|
+
gem.description = %Q{An Object Graph Mapper (OGM) for mapping Ruby Objects onto graphs in a instance or Rexster, like CouchRest is for CouchDB}
|
20
|
+
gem.email = "christopher.petersen@gmail.com"
|
21
|
+
gem.authors = ["Christopher Petersen"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
gem.add_runtime_dependency 'excon', '0.3.6'
|
27
|
+
gem.add_runtime_dependency 'json', '1.2.4'
|
28
|
+
end
|
29
|
+
Jeweler::RubygemsDotOrgTasks.new
|
30
|
+
|
31
|
+
require 'rspec/core'
|
32
|
+
require 'rspec/core/rake_task'
|
33
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
34
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
35
|
+
end
|
36
|
+
|
37
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
38
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
39
|
+
spec.rcov = true
|
40
|
+
end
|
41
|
+
|
42
|
+
task :default => :spec
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "ruxster #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/lib/ruxster/base.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
module Ruxster
|
2
|
+
class Base
|
3
|
+
def initialize(hash={})
|
4
|
+
hash.each { |k,v| properties_hash[k] = v }
|
5
|
+
end
|
6
|
+
def parameterize
|
7
|
+
URI.escape(properties_hash.collect{|k,v| "#{k}=#{v}"}.join('&'))
|
8
|
+
end
|
9
|
+
def properties_hash
|
10
|
+
@properties_hash ||= {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def id
|
14
|
+
properties_hash["_id"]
|
15
|
+
end
|
16
|
+
def id=(value)
|
17
|
+
properties_hash["_id"] = value
|
18
|
+
end
|
19
|
+
def type
|
20
|
+
properties_hash["_type"]
|
21
|
+
end
|
22
|
+
def type=(value)
|
23
|
+
properties_hash["_type"] = value
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.connect_string
|
27
|
+
Ruxster::Config.connect_string
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get(id)
|
31
|
+
object = nil
|
32
|
+
response = Excon.get(Base.connect_string + "/#{self.url_directory}/#{id}")
|
33
|
+
if response
|
34
|
+
results = JSON.parse(response.body)["results"]
|
35
|
+
object = self.new(results) if results
|
36
|
+
end
|
37
|
+
object
|
38
|
+
end
|
39
|
+
|
40
|
+
def create
|
41
|
+
response = Excon.post(Base.connect_string + "/#{self.class.url_directory}?" + parameterize)
|
42
|
+
if response
|
43
|
+
results = JSON.parse(response.body)["results"]
|
44
|
+
properties_hash["_id"] = results["_id"]
|
45
|
+
properties_hash["_type"] = results["_type"]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def update
|
50
|
+
response = Excon.post(Base.connect_string + "/#{self.class.url_directory}/#{self.id}?" + parameterize)
|
51
|
+
end
|
52
|
+
|
53
|
+
def destroy
|
54
|
+
response = Excon.delete(Base.connect_string + "/#{self.class.url_directory}/#{self.id}")
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.find(key, value)
|
58
|
+
response = JSON.parse(Excon.get(Base.connect_string + "/indices/#{url_directory}?key=#{key}&value=#{value}").body)
|
59
|
+
response["results"]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/ruxster/edge.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'excon'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Ruxster
|
5
|
+
class Edge < Base
|
6
|
+
def self.url_directory
|
7
|
+
"edges"
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(hash={})
|
11
|
+
hash.each do |key, value|
|
12
|
+
case key.to_s
|
13
|
+
when "id"
|
14
|
+
self.id = value
|
15
|
+
when "_id"
|
16
|
+
self.id = value
|
17
|
+
when "type"
|
18
|
+
self.type = value
|
19
|
+
when "_type"
|
20
|
+
self.type = value
|
21
|
+
when "_label"
|
22
|
+
self.label = value
|
23
|
+
when "label"
|
24
|
+
self.label = value
|
25
|
+
when "weight"
|
26
|
+
self.weight = value
|
27
|
+
when "_inV"
|
28
|
+
self.in_vertex = value
|
29
|
+
when "in_vertex"
|
30
|
+
self.in_vertex = value
|
31
|
+
when "_outV"
|
32
|
+
self.out_vertex = value
|
33
|
+
when "out_vertex"
|
34
|
+
self.out_vertex = value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def label
|
40
|
+
self.properties_hash["_label"]
|
41
|
+
end
|
42
|
+
def label=(value)
|
43
|
+
self.properties_hash["_label"] = value
|
44
|
+
end
|
45
|
+
|
46
|
+
def weight
|
47
|
+
self.properties_hash["weight"]
|
48
|
+
end
|
49
|
+
def weight=(value)
|
50
|
+
self.properties_hash["weight"] = value.to_i
|
51
|
+
end
|
52
|
+
|
53
|
+
def in_vertex
|
54
|
+
Vertex.get(self.properties_hash["_inV"])
|
55
|
+
end
|
56
|
+
def in_vertex=(value)
|
57
|
+
if value.class == Vertex
|
58
|
+
self.properties_hash["_inV"] = value["_id"]
|
59
|
+
else
|
60
|
+
self.properties_hash["_inV"] = value
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def out_vertex
|
65
|
+
Vertex.get(self.properties_hash["_outV"])
|
66
|
+
end
|
67
|
+
def out_vertex=(value)
|
68
|
+
if value.class == Vertex
|
69
|
+
self.properties_hash["_outV"] = value["_id"]
|
70
|
+
else
|
71
|
+
self.properties_hash["_outV"] = value
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.create(hash={})
|
76
|
+
edge = Edge.new(hash)
|
77
|
+
edge.create
|
78
|
+
edge
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.all
|
82
|
+
objects = []
|
83
|
+
response = Excon.get(Vertex.connect_string + "/edges")
|
84
|
+
if response
|
85
|
+
results = JSON.parse(response.body)["results"]
|
86
|
+
if results
|
87
|
+
results.each do |hash|
|
88
|
+
objects << self.new(hash)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
objects
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'excon'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Ruxster
|
5
|
+
class Vertex < Base
|
6
|
+
def self.url_directory
|
7
|
+
"vertices"
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](key)
|
11
|
+
properties_hash[key]
|
12
|
+
end
|
13
|
+
def []=(key, value)
|
14
|
+
properties_hash[key] = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def out_edges
|
18
|
+
all_edges("outE")
|
19
|
+
end
|
20
|
+
def in_edges
|
21
|
+
all_edges("inE")
|
22
|
+
end
|
23
|
+
def all_edges(which_edges="bothE")
|
24
|
+
edges = []
|
25
|
+
response = Excon.get(Vertex.connect_string + "/vertices/#{self.id}/#{which_edges}")
|
26
|
+
if response
|
27
|
+
results = JSON.parse(response.body)["results"]
|
28
|
+
if results
|
29
|
+
results.each do |hash|
|
30
|
+
edges << Edge.new(hash)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
edges
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.create(hash={})
|
38
|
+
edge = Vertex.new(hash)
|
39
|
+
edge.create
|
40
|
+
edge
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.all
|
44
|
+
objects = []
|
45
|
+
response = Excon.get(Vertex.connect_string + "/vertices")
|
46
|
+
if response
|
47
|
+
results = JSON.parse(response.body)["results"]
|
48
|
+
if results
|
49
|
+
results.each do |hash|
|
50
|
+
objects << self.new(hash)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
objects
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/ruxster.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
libdir = File.dirname(__FILE__)
|
2
|
+
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
3
|
+
|
4
|
+
|
5
|
+
module Ruxster
|
6
|
+
autoload :Base, 'ruxster/base'
|
7
|
+
autoload :Vertex, 'ruxster/vertex'
|
8
|
+
autoload :Edge, 'ruxster/edge'
|
9
|
+
|
10
|
+
class Config
|
11
|
+
def self.connect_string=(value)
|
12
|
+
@@connect_string = value
|
13
|
+
end
|
14
|
+
def self.connect_string
|
15
|
+
@@connect_string
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/ruxster.gemspec
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ruxster}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Christopher Petersen"]
|
12
|
+
s.date = %q{2011-01-11}
|
13
|
+
s.description = %q{An Object Graph Mapper (OGM) for mapping Ruby Objects onto graphs in a instance or Rexster, like CouchRest is for CouchDB}
|
14
|
+
s.email = %q{christopher.petersen@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.textile"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.textile",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/ruxster.rb",
|
27
|
+
"lib/ruxster/base.rb",
|
28
|
+
"lib/ruxster/edge.rb",
|
29
|
+
"lib/ruxster/vertex.rb",
|
30
|
+
"ruxster.gemspec",
|
31
|
+
"spec/base_spec.rb",
|
32
|
+
"spec/edge_spec.rb",
|
33
|
+
"spec/ruxster_spec.rb",
|
34
|
+
"spec/spec.opts",
|
35
|
+
"spec/spec_helper.rb",
|
36
|
+
"spec/vertex_spec.rb"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://github.com/cpetersen/ruxster}
|
39
|
+
s.licenses = ["MIT"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = %q{1.3.6}
|
42
|
+
s.summary = %q{An Object Graph Mapper (OGM) for Rexster}
|
43
|
+
s.test_files = [
|
44
|
+
"spec/base_spec.rb",
|
45
|
+
"spec/edge_spec.rb",
|
46
|
+
"spec/ruxster_spec.rb",
|
47
|
+
"spec/spec_helper.rb",
|
48
|
+
"spec/vertex_spec.rb"
|
49
|
+
]
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_runtime_dependency(%q<json>, ["~> 1.2.4"])
|
57
|
+
s.add_runtime_dependency(%q<excon>, ["~> 0.3.6"])
|
58
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
59
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
61
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<rspec>, ["> 1.2.3"])
|
63
|
+
s.add_runtime_dependency(%q<excon>, ["= 0.3.6"])
|
64
|
+
s.add_runtime_dependency(%q<json>, ["= 1.2.4"])
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<json>, ["~> 1.2.4"])
|
67
|
+
s.add_dependency(%q<excon>, ["~> 0.3.6"])
|
68
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
69
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
71
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rspec>, ["> 1.2.3"])
|
73
|
+
s.add_dependency(%q<excon>, ["= 0.3.6"])
|
74
|
+
s.add_dependency(%q<json>, ["= 1.2.4"])
|
75
|
+
end
|
76
|
+
else
|
77
|
+
s.add_dependency(%q<json>, ["~> 1.2.4"])
|
78
|
+
s.add_dependency(%q<excon>, ["~> 0.3.6"])
|
79
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
80
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
81
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
82
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
83
|
+
s.add_dependency(%q<rspec>, ["> 1.2.3"])
|
84
|
+
s.add_dependency(%q<excon>, ["= 0.3.6"])
|
85
|
+
s.add_dependency(%q<json>, ["= 1.2.4"])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
data/spec/base_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Ruxster::Base" do
|
4
|
+
before(:all) do
|
5
|
+
Ruxster::Config.connect_string = "http://localhost:8182/database"
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should have the connect string" do
|
9
|
+
Ruxster::Base.connect_string.should == "http://localhost:8182/database"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have a property_hash" do
|
13
|
+
Ruxster::Base.new.properties_hash.should == {}
|
14
|
+
end
|
15
|
+
it "should properly set id" do
|
16
|
+
base = Ruxster::Base.new
|
17
|
+
base.id = "id"
|
18
|
+
base.properties_hash["_id"].should == "id"
|
19
|
+
base.id.should == "id"
|
20
|
+
end
|
21
|
+
it "should properly set type" do
|
22
|
+
base = Ruxster::Base.new
|
23
|
+
base.type = "type"
|
24
|
+
base.properties_hash["_type"].should == "type"
|
25
|
+
base.type.should == "type"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should initialize properly from a hash" do
|
29
|
+
base = Ruxster::Base.new("_id" => "id", "name" => "name_value", "rank" => 5)
|
30
|
+
base.properties_hash["_id"].should == "id"
|
31
|
+
base.properties_hash["name"].should == "name_value"
|
32
|
+
base.properties_hash["rank"].should == 5
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should properly encode it's parameters" do
|
36
|
+
base = Ruxster::Base.new("_id" => "id", "name" => "name_value", "rank" => 5)
|
37
|
+
base.parameterize.should == "name=name_value&_id=id&rank=5"
|
38
|
+
end
|
39
|
+
end
|
data/spec/edge_spec.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Ruxster::Edge" do
|
4
|
+
before(:all) do
|
5
|
+
Ruxster::Config.connect_string = "http://localhost:8182/database"
|
6
|
+
@vertex1 = Ruxster::Vertex.create("name" => "Vertex 1")
|
7
|
+
@vertex2 = Ruxster::Vertex.create("name" => "Vertex 2")
|
8
|
+
@edge = Ruxster::Edge.new("_label" => "label", "weight" => 15)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should initialize properly from a hash" do
|
12
|
+
@edge.label.should == "label"
|
13
|
+
@edge.weight.should == 15
|
14
|
+
end
|
15
|
+
|
16
|
+
it "it should set _inV when in_vertex is called" do
|
17
|
+
@edge.in_vertex = @vertex1
|
18
|
+
@edge.properties_hash["_inV"].should == @vertex1.id
|
19
|
+
@edge.in_vertex.id.should == @vertex1.id
|
20
|
+
end
|
21
|
+
|
22
|
+
it "it should set _outV when out_vertex is called" do
|
23
|
+
@edge.out_vertex = @vertex2
|
24
|
+
@edge.properties_hash["_outV"].should == @vertex2.id
|
25
|
+
@edge.out_vertex.id.should == @vertex2.id
|
26
|
+
end
|
27
|
+
|
28
|
+
it "it should set label properly" do
|
29
|
+
@edge.label = "label"
|
30
|
+
@edge.properties_hash["_label"].should == "label"
|
31
|
+
@edge.label.should == "label"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "it should set weight properly" do
|
35
|
+
@edge.weight = 15
|
36
|
+
@edge.properties_hash["weight"].should == 15
|
37
|
+
@edge.weight.should == 15
|
38
|
+
end
|
39
|
+
|
40
|
+
it "it should set weight properly when using a string" do
|
41
|
+
@edge.weight = "15"
|
42
|
+
@edge.properties_hash["weight"].should == 15
|
43
|
+
@edge.weight.should == 15
|
44
|
+
end
|
45
|
+
|
46
|
+
it "it should set weight properly when passed nil" do
|
47
|
+
@edge.weight = nil
|
48
|
+
@edge.properties_hash["weight"].should == 0
|
49
|
+
@edge.weight.should == 0
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should post to the proper url upon create" do
|
53
|
+
edge = Ruxster::Edge.new("_label" => "label", "weight" => 15, :in_vertex => @vertex1, :out_vertex => @vertex2)
|
54
|
+
Excon.should_receive(:post).with("http://localhost:8182/database/edges?_label=label&weight=15&_outV=#{@vertex2.id}&_inV=#{@vertex1.id}")
|
55
|
+
edge.create
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should add a vertex when Class.create is called" do
|
59
|
+
original_vertex_count = Ruxster::Edge.all.count
|
60
|
+
Ruxster::Edge.create("label" => "label_value", :in_vertex => @vertex1, :out_vertex => @vertex2)
|
61
|
+
Ruxster::Edge.all.count.should == original_vertex_count+1
|
62
|
+
end
|
63
|
+
|
64
|
+
it "find the right edge" do
|
65
|
+
results = Ruxster::Edge.find("weight", 15)
|
66
|
+
results.first["weight"].should == "15"
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "after create" do
|
70
|
+
before(:all) do
|
71
|
+
@original_edge_count = Ruxster::Edge.all.count
|
72
|
+
@edge.in_vertex = @vertex1
|
73
|
+
@edge.out_vertex = @vertex2
|
74
|
+
@edge.create
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should add a edge to the database" do
|
78
|
+
Ruxster::Edge.all.count.should == @original_edge_count+1
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should set the _id property after create" do
|
82
|
+
@edge.id.should_not be_nil
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should set the _type property after create" do
|
86
|
+
@edge.type.should == "edge"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should return the edge when get is called" do
|
90
|
+
edge = Ruxster::Edge.get(@edge.id)
|
91
|
+
edge.id.should == @edge.id
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should update the database when update is called" do
|
95
|
+
@edge.weight = 25
|
96
|
+
@edge.update
|
97
|
+
edge = Ruxster::Edge.get(@edge.id)
|
98
|
+
edge.weight.should == 25
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should update the database when weight is updated to nil" do
|
102
|
+
@edge.weight = nil
|
103
|
+
@edge.update
|
104
|
+
edge = Ruxster::Edge.get(@edge.id)
|
105
|
+
edge.weight.should == 0
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should remove the edge from the database when destroy is called" do
|
109
|
+
edge_count = Ruxster::Edge.all.count
|
110
|
+
@edge.destroy
|
111
|
+
Ruxster::Edge.all.count.should == edge_count-1
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should return all edges in the database when all is called" do
|
116
|
+
edges = Ruxster::Edge.all
|
117
|
+
edges.class.should == Array
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Ruxster" do
|
4
|
+
it "should store the connect string" do
|
5
|
+
Ruxster::Config.connect_string = "http://localhost:8182/database"
|
6
|
+
Ruxster::Config.connect_string.should == "http://localhost:8182/database"
|
7
|
+
end
|
8
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'ruxster'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
data/spec/vertex_spec.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Ruxster::Vertex" do
|
4
|
+
before(:all) do
|
5
|
+
Ruxster::Config.connect_string = "http://localhost:8182/database"
|
6
|
+
@vertex = Ruxster::Vertex.new("name" => "name_value")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should post to the proper url upon create" do
|
10
|
+
Excon.should_receive(:post).with("http://localhost:8182/database/vertices?name=name_value")
|
11
|
+
@vertex.create
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should initialize properly from a hash" do
|
15
|
+
@vertex["name"].should == "name_value"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should add a vertex when Class.create is called" do
|
19
|
+
original_vertex_count = Ruxster::Vertex.all.count
|
20
|
+
Ruxster::Vertex.create("name" => "name_value")
|
21
|
+
Ruxster::Vertex.all.count.should == original_vertex_count+1
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "after create" do
|
25
|
+
before(:all) do
|
26
|
+
@original_vertex_count = Ruxster::Vertex.all.count
|
27
|
+
@vertex.create
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should add a vertex to the database" do
|
31
|
+
Ruxster::Vertex.all.count.should == @original_vertex_count+1
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should set the _id property after create" do
|
35
|
+
@vertex["_id"].should_not be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should set the _type property after create" do
|
39
|
+
@vertex["_type"].should == "vertex"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return the vertex when get is called" do
|
43
|
+
vertex = Ruxster::Vertex.get(@vertex["_id"])
|
44
|
+
vertex["_id"].should == @vertex["_id"]
|
45
|
+
vertex["name"].should == @vertex["name"]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should update the database when update is called" do
|
49
|
+
@vertex["name"] = "new_name"
|
50
|
+
@vertex.update
|
51
|
+
vertex = Ruxster::Vertex.get(@vertex["_id"])
|
52
|
+
vertex["name"].should == "new_name"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should remove the vertex from the database when destroy is called" do
|
56
|
+
vertex_count = Ruxster::Vertex.all.count
|
57
|
+
@vertex.destroy
|
58
|
+
Ruxster::Vertex.all.count.should == vertex_count-1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "a small network of 3 vertices and 4 edges" do
|
63
|
+
before(:all) do
|
64
|
+
@jack = Ruxster::Vertex.create("name" => "Jack")
|
65
|
+
@jill = Ruxster::Vertex.create("name" => "Jill")
|
66
|
+
@tommy_boy = Ruxster::Vertex.create("name" => "Tommy Boy")
|
67
|
+
@jack_clicked_tommy_boy = Ruxster::Edge.create("_label" => "clicked", "weight" => 15, :in_vertex => @tommy_boy, :out_vertex => @jack)
|
68
|
+
@jill_clicked_tommy_boy = Ruxster::Edge.create("_label" => "clicked", "weight" => 15, :in_vertex => @tommy_boy, :out_vertex => @jill)
|
69
|
+
@jack_bought_tommy_boy = Ruxster::Edge.create("_label" => "bought", "weight" => 15, :in_vertex => @tommy_boy, :out_vertex => @jack)
|
70
|
+
@jill_likes_jack = Ruxster::Edge.create("_label" => "likes", "weight" => 15, :in_vertex => @jack, :out_vertex => @jill)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "Tommy Boy should have 3 In Edges" do
|
74
|
+
@tommy_boy.in_edges.count.should == 3
|
75
|
+
end
|
76
|
+
it "Jack should have 2 Out Edges" do
|
77
|
+
@jack.out_edges.count.should == 2
|
78
|
+
end
|
79
|
+
it "Jack should have 3 Total Edges" do
|
80
|
+
@jack.all_edges.count.should == 3
|
81
|
+
end
|
82
|
+
|
83
|
+
it "find the right vertex" do
|
84
|
+
results = Ruxster::Vertex.find("name", "Jack")
|
85
|
+
results.first["name"].should == "Jack"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should return all vertices in the database when all is called" do
|
90
|
+
vertices = Ruxster::Vertex.all
|
91
|
+
vertices.class.should == Array
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruxster
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Christopher Petersen
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-11 00:00:00 -08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ~>
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
segments:
|
26
|
+
- 1
|
27
|
+
- 2
|
28
|
+
- 4
|
29
|
+
version: 1.2.4
|
30
|
+
prerelease: false
|
31
|
+
type: :runtime
|
32
|
+
name: json
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
- 3
|
42
|
+
- 6
|
43
|
+
version: 0.3.6
|
44
|
+
prerelease: false
|
45
|
+
type: :runtime
|
46
|
+
name: excon
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 2
|
55
|
+
- 3
|
56
|
+
- 0
|
57
|
+
version: 2.3.0
|
58
|
+
prerelease: false
|
59
|
+
type: :development
|
60
|
+
name: rspec
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 1
|
69
|
+
- 0
|
70
|
+
- 0
|
71
|
+
version: 1.0.0
|
72
|
+
prerelease: false
|
73
|
+
type: :development
|
74
|
+
name: bundler
|
75
|
+
version_requirements: *id004
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ~>
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 1
|
83
|
+
- 5
|
84
|
+
- 2
|
85
|
+
version: 1.5.2
|
86
|
+
prerelease: false
|
87
|
+
type: :development
|
88
|
+
name: jeweler
|
89
|
+
version_requirements: *id005
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
prerelease: false
|
99
|
+
type: :development
|
100
|
+
name: rcov
|
101
|
+
version_requirements: *id006
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
segments:
|
108
|
+
- 1
|
109
|
+
- 2
|
110
|
+
- 3
|
111
|
+
version: 1.2.3
|
112
|
+
prerelease: false
|
113
|
+
type: :development
|
114
|
+
name: rspec
|
115
|
+
version_requirements: *id007
|
116
|
+
- !ruby/object:Gem::Dependency
|
117
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - "="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
- 3
|
124
|
+
- 6
|
125
|
+
version: 0.3.6
|
126
|
+
prerelease: false
|
127
|
+
type: :runtime
|
128
|
+
name: excon
|
129
|
+
version_requirements: *id008
|
130
|
+
- !ruby/object:Gem::Dependency
|
131
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - "="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
segments:
|
136
|
+
- 1
|
137
|
+
- 2
|
138
|
+
- 4
|
139
|
+
version: 1.2.4
|
140
|
+
prerelease: false
|
141
|
+
type: :runtime
|
142
|
+
name: json
|
143
|
+
version_requirements: *id009
|
144
|
+
description: An Object Graph Mapper (OGM) for mapping Ruby Objects onto graphs in a instance or Rexster, like CouchRest is for CouchDB
|
145
|
+
email: christopher.petersen@gmail.com
|
146
|
+
executables: []
|
147
|
+
|
148
|
+
extensions: []
|
149
|
+
|
150
|
+
extra_rdoc_files:
|
151
|
+
- LICENSE.txt
|
152
|
+
- README.textile
|
153
|
+
files:
|
154
|
+
- .document
|
155
|
+
- Gemfile
|
156
|
+
- LICENSE.txt
|
157
|
+
- README.textile
|
158
|
+
- Rakefile
|
159
|
+
- VERSION
|
160
|
+
- lib/ruxster.rb
|
161
|
+
- lib/ruxster/base.rb
|
162
|
+
- lib/ruxster/edge.rb
|
163
|
+
- lib/ruxster/vertex.rb
|
164
|
+
- ruxster.gemspec
|
165
|
+
- spec/base_spec.rb
|
166
|
+
- spec/edge_spec.rb
|
167
|
+
- spec/ruxster_spec.rb
|
168
|
+
- spec/spec.opts
|
169
|
+
- spec/spec_helper.rb
|
170
|
+
- spec/vertex_spec.rb
|
171
|
+
has_rdoc: true
|
172
|
+
homepage: http://github.com/cpetersen/ruxster
|
173
|
+
licenses:
|
174
|
+
- MIT
|
175
|
+
post_install_message:
|
176
|
+
rdoc_options: []
|
177
|
+
|
178
|
+
require_paths:
|
179
|
+
- lib
|
180
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
segments:
|
185
|
+
- 0
|
186
|
+
version: "0"
|
187
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
|
+
requirements:
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
segments:
|
192
|
+
- 0
|
193
|
+
version: "0"
|
194
|
+
requirements: []
|
195
|
+
|
196
|
+
rubyforge_project:
|
197
|
+
rubygems_version: 1.3.6
|
198
|
+
signing_key:
|
199
|
+
specification_version: 3
|
200
|
+
summary: An Object Graph Mapper (OGM) for Rexster
|
201
|
+
test_files:
|
202
|
+
- spec/base_spec.rb
|
203
|
+
- spec/edge_spec.rb
|
204
|
+
- spec/ruxster_spec.rb
|
205
|
+
- spec/spec_helper.rb
|
206
|
+
- spec/vertex_spec.rb
|