keymaker 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +75 -1
- data/keymaker.gemspec +3 -3
- data/lib/keymaker.rb +1 -1
- data/lib/keymaker/rails_tasks.rb +68 -0
- data/spec/keymaker_spec.rb +1 -1
- data/spec/support/keymaker.rb +4 -4
- metadata +4 -4
- data/keymaker_integration_spec.rb +0 -182
data/Rakefile
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
#############################################################################
|
3
2
|
#
|
4
3
|
# Helper functions
|
@@ -121,3 +120,78 @@ task :validate do
|
|
121
120
|
exit!
|
122
121
|
end
|
123
122
|
end
|
123
|
+
|
124
|
+
#############################################################################
|
125
|
+
#
|
126
|
+
# Neo4j tasks
|
127
|
+
#
|
128
|
+
#############################################################################
|
129
|
+
|
130
|
+
KEYMAKER_ROOT = File.expand_path(File.dirname(__FILE__) + '/../..')
|
131
|
+
KEYMAKER_TMP_DIR = File.expand_path(File.join(KEYMAKER_ROOT, "tmp"))
|
132
|
+
NEO4J_INSTALL_DIR = ENV['NEO4J_INSTALL_DIR'] || File.expand_path(File.join(KEYMAKER_TMP_DIR, "keymaker_development"))
|
133
|
+
NEO4J_PORT = ENV['NEO4J_PORT'] || '7477' # Don't clobber standard neo4j ports 7474 or 7475 for development
|
134
|
+
|
135
|
+
namespace :neo4j do
|
136
|
+
|
137
|
+
desc "Install neo4j on localhost:#{NEO4J_PORT}. e.g. rake neo4j:install[community,1.7.M03]"
|
138
|
+
task :install, :edition, :version do |t, args|
|
139
|
+
args.with_defaults(:edition => "community", :version => "1.7")
|
140
|
+
|
141
|
+
source_name = "neo4j-#{args[:edition]}-#{args[:version]}"
|
142
|
+
tarball = "#{source_name}-unix.tar.gz"
|
143
|
+
|
144
|
+
puts "Installing #{source_name} to localhost:#{NEO4J_PORT}..."
|
145
|
+
|
146
|
+
ssl_url_true = "org.neo4j.server.webserver.https.enabled=true"
|
147
|
+
ssl_url_false = ssl_url_true.gsub("true","false")
|
148
|
+
|
149
|
+
%x[mkdir -p #{KEYMAKER_TMP_DIR}; cd #{KEYMAKER_TMP_DIR}]
|
150
|
+
FileUtils.rm_rf(NEO4J_INSTALL_DIR) if Dir.exists?(NEO4J_INSTALL_DIR) && File.owned?(NEO4J_INSTALL_DIR)
|
151
|
+
%x[wget http://dist.neo4j.org/#{tarball}]
|
152
|
+
%x[tar xvzf #{tarball}]
|
153
|
+
|
154
|
+
%x[mv #{source_name} #{NEO4J_INSTALL_DIR}]
|
155
|
+
%x[rm #{tarball}]
|
156
|
+
|
157
|
+
%x[sed -i.bak 's/7474/#{NEO4J_PORT}/g' #{NEO4J_INSTALL_DIR}/conf/neo4j-server.properties]
|
158
|
+
%x[sed -i.bak 's/#{ssl_url_true}/#{ssl_url_false}/g' #{NEO4J_INSTALL_DIR}/conf/neo4j-server.properties]
|
159
|
+
|
160
|
+
puts "#{source_name} Installed into the #{NEO4J_INSTALL_DIR} directory."
|
161
|
+
puts "Run `rake neo4j:start` to start it"
|
162
|
+
end
|
163
|
+
|
164
|
+
desc "Start the neo4j server running on localhost:#{NEO4J_PORT}"
|
165
|
+
task :start do
|
166
|
+
puts "Starting neo4j for keymaker_development..."
|
167
|
+
%x[#{NEO4J_INSTALL_DIR}/bin/neo4j start]
|
168
|
+
end
|
169
|
+
|
170
|
+
desc "Stop the neo4j server running on localhost:#{NEO4J_PORT}"
|
171
|
+
task :stop do
|
172
|
+
puts "Stopping neo4j for keymaker_development..."
|
173
|
+
%x[#{NEO4J_INSTALL_DIR}/bin/neo4j stop]
|
174
|
+
end
|
175
|
+
|
176
|
+
desc "Restart the neo4j server running on localhost:#{NEO4J_PORT}"
|
177
|
+
task :restart do
|
178
|
+
puts "Restarting neo4j for keymaker_development..."
|
179
|
+
%x[#{NEO4J_INSTALL_DIR}/bin/neo4j restart]
|
180
|
+
end
|
181
|
+
|
182
|
+
desc "Wipe out and recreate the neo4j server running on localhost:#{NEO4J_PORT}"
|
183
|
+
task :reset do
|
184
|
+
puts "Resetting neo4j for keymaker_development..."
|
185
|
+
# Stop the server
|
186
|
+
%x[#{NEO4J_INSTALL_DIR}/bin/neo4j stop]
|
187
|
+
# Reset the database
|
188
|
+
FileUtils.rm_rf("#{NEO4J_INSTALL_DIR}/data/graph.db")
|
189
|
+
FileUtils.mkdir("#{NEO4J_INSTALL_DIR}/data/graph.db")
|
190
|
+
# Remove log files
|
191
|
+
FileUtils.rm_rf("#{NEO4J_INSTALL_DIR}/data/log")
|
192
|
+
FileUtils.mkdir("#{NEO4J_INSTALL_DIR}/data/log")
|
193
|
+
# Start the server
|
194
|
+
%x[#{NEO4J_INSTALL_DIR}/bin/neo4j start]
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
data/keymaker.gemspec
CHANGED
@@ -14,8 +14,8 @@ Gem::Specification.new do |s|
|
|
14
14
|
## If your rubyforge_project name is different, then edit it and comment out
|
15
15
|
## the sub! line in the Rakefile
|
16
16
|
s.name = 'keymaker'
|
17
|
-
s.version = '0.0.
|
18
|
-
s.date = '2012-06-
|
17
|
+
s.version = '0.0.3'
|
18
|
+
s.date = '2012-06-15'
|
19
19
|
|
20
20
|
## Make sure your summary is short. The description may be as long
|
21
21
|
## as you like.
|
@@ -63,7 +63,6 @@ Gem::Specification.new do |s|
|
|
63
63
|
README.md
|
64
64
|
Rakefile
|
65
65
|
keymaker.gemspec
|
66
|
-
keymaker_integration_spec.rb
|
67
66
|
lib/keymaker.rb
|
68
67
|
lib/keymaker/add_node_to_index_request.rb
|
69
68
|
lib/keymaker/batch_get_nodes_request.rb
|
@@ -76,6 +75,7 @@ Gem::Specification.new do |s|
|
|
76
75
|
lib/keymaker/indexing.rb
|
77
76
|
lib/keymaker/node.rb
|
78
77
|
lib/keymaker/path_traverse_request.rb
|
78
|
+
lib/keymaker/rails_tasks.rb
|
79
79
|
lib/keymaker/remove_node_from_index_request.rb
|
80
80
|
lib/keymaker/request.rb
|
81
81
|
lib/keymaker/response.rb
|
data/lib/keymaker.rb
CHANGED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Inspired by the neo4j tasks in maxdemarzi/neography
|
2
|
+
NEO4J_INSTALL_DIR = ENV['NEO4J_INSTALL_DIR'] || File.expand_path(File.join(Rails.root, "tmp", "neo_#{Rails.env}"))
|
3
|
+
NEO4J_PORT = ENV['NEO4J_PORT'] || Rails.env.test? ? "7475" : "7474"
|
4
|
+
|
5
|
+
namespace :neo4j do
|
6
|
+
|
7
|
+
desc "Install Neo4j for the current environment. e.g. rake neo4j:install or rake neo4j:install RAILS_ENV=test"
|
8
|
+
task :install, [:edition, :version] => [:environment] do |t, args|
|
9
|
+
args.with_defaults(:edition => "community", :version => "1.7")
|
10
|
+
source_name = "neo4j-#{args[:edition]}-#{args[:version]}"
|
11
|
+
tarball = "#{source_name}-unix.tar.gz"
|
12
|
+
|
13
|
+
puts "Installing #{source_name} for #{Rails.env} to localhost:#{NEO4J_PORT}..."
|
14
|
+
|
15
|
+
ssl_url_true = "org.neo4j.server.webserver.https.enabled=true"
|
16
|
+
ssl_url_false = ssl_url_true.gsub("true","false")
|
17
|
+
|
18
|
+
FileUtils.rm_rf(NEO4J_INSTALL_DIR) if Dir.exists?(NEO4J_INSTALL_DIR) && File.owned?(NEO4J_INSTALL_DIR)
|
19
|
+
%x[wget http://dist.neo4j.org/#{tarball}]
|
20
|
+
%x[tar xvzf #{tarball}]
|
21
|
+
|
22
|
+
%x[mv #{source_name} #{NEO4J_INSTALL_DIR}]
|
23
|
+
%x[rm #{tarball}]
|
24
|
+
|
25
|
+
%x[sed -i.bak 's/7474/#{NEO4J_PORT}/g' #{NEO4J_INSTALL_DIR}/conf/neo4j-server.properties]
|
26
|
+
%x[sed -i.bak 's/#{ssl_url_true}/#{ssl_url_false}/g' #{NEO4J_INSTALL_DIR}/conf/neo4j-server.properties]
|
27
|
+
|
28
|
+
puts "Installed #{source_name} for #{Rails.env} to localhost:#{NEO4J_PORT}..."
|
29
|
+
puts "Run `#{"RAILS_ENV=#{Rails.env} " if Rails.env.test?}rake neo4j:start` to start it"
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Start the Neo4j Server"
|
33
|
+
task :start => :environment do
|
34
|
+
puts "Starting Neo4j for #{Rails.env} on localhost:#{NEO4J_PORT}..."
|
35
|
+
%x[#{NEO4J_INSTALL_DIR}/bin/neo4j start]
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Stop the Neo4j Server"
|
39
|
+
task :stop => :environment do
|
40
|
+
puts "Stopping Neo4j for #{Rails.env} on localhost:#{NEO4J_PORT}..."
|
41
|
+
%x[#{NEO4J_INSTALL_DIR}/bin/neo4j stop]
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "Restart the Neo4j Server"
|
45
|
+
task :restart => :environment do
|
46
|
+
puts "Restarting Neo4j for #{Rails.env} on localhost:#{NEO4J_PORT}..."
|
47
|
+
%x[#{NEO4J_INSTALL_DIR}/bin/neo4j restart]
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "Reset the Neo4j Server"
|
51
|
+
task :reset => :environment do
|
52
|
+
puts "Resetting Neo4j for #{Rails.env} on localhost:#{NEO4J_PORT}..."
|
53
|
+
# Stop the server
|
54
|
+
%x[#{NEO4J_INSTALL_DIR}/bin/neo4j stop]
|
55
|
+
|
56
|
+
# Reset the database
|
57
|
+
FileUtils.rm_rf("#{NEO4J_INSTALL_DIR}/data/graph.db")
|
58
|
+
FileUtils.mkdir("#{NEO4J_INSTALL_DIR}/data/graph.db")
|
59
|
+
|
60
|
+
# Remove log files
|
61
|
+
FileUtils.rm_rf("#{NEO4J_INSTALL_DIR}/data/log")
|
62
|
+
FileUtils.mkdir("#{NEO4J_INSTALL_DIR}/data/log")
|
63
|
+
|
64
|
+
# Start the server
|
65
|
+
%x[#{NEO4J_INSTALL_DIR}/bin/neo4j start]
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
data/spec/keymaker_spec.rb
CHANGED
data/spec/support/keymaker.rb
CHANGED
@@ -2,12 +2,12 @@ require 'keymaker'
|
|
2
2
|
|
3
3
|
Keymaker.configure do |c|
|
4
4
|
c.server = "localhost"
|
5
|
-
c.port =
|
5
|
+
c.port = 7477
|
6
6
|
end
|
7
7
|
|
8
8
|
shared_context "Keymaker connections" do
|
9
9
|
let(:connection) do
|
10
|
-
Faraday.new({url: "http://localhost:
|
10
|
+
Faraday.new({url: "http://localhost:7477"}) do |conn|
|
11
11
|
conn.request :json
|
12
12
|
conn.use FaradayMiddleware::ParseJson, content_type: /\bjson$/
|
13
13
|
conn.adapter :net_http
|
@@ -81,11 +81,11 @@ def clear_graph
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def clear_users_index
|
84
|
-
raw_connection.delete("http://localhost:
|
84
|
+
raw_connection.delete("http://localhost:7477/db/data/index/node/users")
|
85
85
|
end
|
86
86
|
|
87
87
|
def raw_connection
|
88
|
-
Faraday.new({url: "http://localhost:
|
88
|
+
Faraday.new({url: "http://localhost:7477"}) do |conn|
|
89
89
|
conn.request :json
|
90
90
|
conn.use FaradayMiddleware::ParseJson, content_type: /\bjson$/
|
91
91
|
conn.adapter :net_http
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keymaker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-06-
|
13
|
+
date: 2012-06-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: addressable
|
@@ -139,7 +139,6 @@ files:
|
|
139
139
|
- README.md
|
140
140
|
- Rakefile
|
141
141
|
- keymaker.gemspec
|
142
|
-
- keymaker_integration_spec.rb
|
143
142
|
- lib/keymaker.rb
|
144
143
|
- lib/keymaker/add_node_to_index_request.rb
|
145
144
|
- lib/keymaker/batch_get_nodes_request.rb
|
@@ -152,6 +151,7 @@ files:
|
|
152
151
|
- lib/keymaker/indexing.rb
|
153
152
|
- lib/keymaker/node.rb
|
154
153
|
- lib/keymaker/path_traverse_request.rb
|
154
|
+
- lib/keymaker/rails_tasks.rb
|
155
155
|
- lib/keymaker/remove_node_from_index_request.rb
|
156
156
|
- lib/keymaker/request.rb
|
157
157
|
- lib/keymaker/response.rb
|
@@ -177,7 +177,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
177
|
version: '0'
|
178
178
|
segments:
|
179
179
|
- 0
|
180
|
-
hash:
|
180
|
+
hash: 2452337814492070163
|
181
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
182
|
none: false
|
183
183
|
requirements:
|
@@ -1,182 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Keymaker do
|
4
|
-
|
5
|
-
include_context "John and Sarah nodes"
|
6
|
-
|
7
|
-
context "indeces" do
|
8
|
-
include_context "John and Sarah indexed nodes"
|
9
|
-
|
10
|
-
context "given a bad port number" do
|
11
|
-
|
12
|
-
let(:url) { john_node_url.dup.gsub("7475", "49152") }
|
13
|
-
|
14
|
-
after { service.connection = connection }
|
15
|
-
|
16
|
-
def do_it
|
17
|
-
connection.get(url)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "raises an error" do
|
21
|
-
expect { do_it }.to raise_error
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
context "given an explicit connection" do
|
27
|
-
|
28
|
-
let(:url) { john_node_url }
|
29
|
-
|
30
|
-
before { service.connection = test_connection }
|
31
|
-
after { service.connection = connection }
|
32
|
-
|
33
|
-
def do_it
|
34
|
-
service.connection.get(url)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "uses the connection for requests" do
|
38
|
-
faraday_stubs.get(Addressable::URI.parse(url).path) do
|
39
|
-
[200, {}, "{}"]
|
40
|
-
end
|
41
|
-
do_it
|
42
|
-
faraday_stubs.verify_stubbed_calls
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#add_node_to_index(index_name, key, value, node_id)" do
|
48
|
-
|
49
|
-
def do_it
|
50
|
-
service.add_node_to_index(:users, :email, email, node_id)
|
51
|
-
end
|
52
|
-
|
53
|
-
context "given existing values" do
|
54
|
-
|
55
|
-
let(:email) { john_email }
|
56
|
-
let(:node_id) { john_node_id }
|
57
|
-
|
58
|
-
it "adds the node to the index" do
|
59
|
-
do_it
|
60
|
-
connection.get(index_query_for_john_url).body.should be_present
|
61
|
-
end
|
62
|
-
|
63
|
-
it "returns a status of 201" do
|
64
|
-
do_it.status.should == 201
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
context "given an invalid node id" do
|
70
|
-
|
71
|
-
let(:email) { john_email }
|
72
|
-
let(:node_id) { -22 }
|
73
|
-
|
74
|
-
it "returns a 500 status" do
|
75
|
-
do_it.status.should == 500
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "#remove_node_from_index(index_name, key, value, node_id)" do
|
83
|
-
|
84
|
-
def do_it
|
85
|
-
service.remove_node_from_index(:users, :email, email, node_id)
|
86
|
-
end
|
87
|
-
|
88
|
-
context "given existing values" do
|
89
|
-
|
90
|
-
let(:email) { john_email }
|
91
|
-
let(:node_id) { john_node_id }
|
92
|
-
|
93
|
-
it "removes the node from the index" do
|
94
|
-
do_it
|
95
|
-
connection.get(index_query_for_john_url).body.should be_empty
|
96
|
-
end
|
97
|
-
|
98
|
-
it "returns a status of 204" do
|
99
|
-
do_it.status.should == 204
|
100
|
-
end
|
101
|
-
|
102
|
-
it "keeps the other node indices" do
|
103
|
-
do_it
|
104
|
-
connection.get(index_query_for_sarah_url).body.should_not be_empty
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
context "given unmatched values" do
|
110
|
-
|
111
|
-
let(:email) { "unknown@example.com" }
|
112
|
-
let(:node_id) { -22 }
|
113
|
-
|
114
|
-
it "returns a 404 status" do
|
115
|
-
do_it.status.should == 404
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe "#execute_query" do
|
124
|
-
|
125
|
-
def do_it
|
126
|
-
service.execute_query("START user=node:users(email={email} RETURN user", email: john_email)
|
127
|
-
end
|
128
|
-
|
129
|
-
context "given existing values" do
|
130
|
-
|
131
|
-
before { service.add_node_to_index(:users, :email, john_email, john_node_id) }
|
132
|
-
|
133
|
-
it "performs the cypher query and responds" do
|
134
|
-
do_it.should be_present
|
135
|
-
end
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
context "nodes" do
|
142
|
-
|
143
|
-
include_context "Keymaker connections"
|
144
|
-
|
145
|
-
describe "#create_node" do
|
146
|
-
|
147
|
-
let(:properties) { { first_name: "john", last_name: "connor", email: "john@resistance.net" } }
|
148
|
-
|
149
|
-
def do_it
|
150
|
-
new_node_id = service.create_node(properties).neo4j_id
|
151
|
-
connection.get("/db/data/node/#{new_node_id}/properties").body
|
152
|
-
end
|
153
|
-
|
154
|
-
it "creates a node with properties" do
|
155
|
-
do_it.should == {"first_name"=>"john", "email"=>"john@resistance.net", "last_name"=>"connor"}
|
156
|
-
end
|
157
|
-
|
158
|
-
end
|
159
|
-
|
160
|
-
end
|
161
|
-
|
162
|
-
context "relationships" do
|
163
|
-
|
164
|
-
include_context "Keymaker connections"
|
165
|
-
|
166
|
-
describe "#create_relationship" do
|
167
|
-
|
168
|
-
def do_it
|
169
|
-
service.create_relationship(:loves, john_node_id, sarah_node_id).neo4j_id
|
170
|
-
connection.get("/db/data/node/#{john_node_id}/relationships/all/loves").body.first
|
171
|
-
end
|
172
|
-
|
173
|
-
it "creates the relationship between the two nodes" do
|
174
|
-
do_it["start"].should == john_node_url
|
175
|
-
do_it["end"].should == sarah_node_url
|
176
|
-
end
|
177
|
-
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|