-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make configuration a more 'rubyish'.
- Loading branch information
Roel van Dijk
committed
Sep 24, 2012
1 parent
317a44d
commit bee8025
Showing
6 changed files
with
209 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,25 +84,49 @@ rake neo4j:install requires wget to be installed. It will download and install | |
|
||
=== Documentation | ||
|
||
@neo = Neography::Rest.new({:protocol => 'http://', | ||
:server => 'localhost', | ||
:port => 7474, | ||
:directory => '', # use '/<my directory>' or leave out for default | ||
:authentication => 'basic', # 'basic', 'digest' or leave out for default | ||
:username => 'your username', #leave out for default | ||
:password => 'your password', #leave out for default | ||
:log_file => 'neography.log', | ||
:log_enabled => false, | ||
:max_threads => 20, | ||
:cypher_path => '/cypher', | ||
:gremlin_path => '/ext/GremlinPlugin/graphdb/execute_script'}) | ||
Configure Neography as follows: | ||
|
||
# these are the default values: | ||
Neography.configure do |config| | ||
config.protocol = "http://" | ||
config.server = "localhost" | ||
config.port = 7474 | ||
config.directory = "" # prefix this path with '/' | ||
config.cypher_path = "/cypher" | ||
config.gremlin_path = "/ext/GremlinPlugin/graphdb/execute_script" | ||
config.log_file = "neography.log" | ||
config.log_enabled = false | ||
config.max_threads = 20 | ||
config.authentication = nil # 'basic' or 'digest' | ||
config.username = nil | ||
config.password = nil | ||
config.parser = {:parser => MultiJsonParser} | ||
end | ||
|
||
Then initialize as follows: | ||
|
||
@neo = Neography::Rest.new | ||
|
||
Or you can override the configured values as follows: | ||
|
||
@neo = Neography::Rest.new({ :protocol => 'http://', | ||
:server => 'localhost', | ||
:port => 7474, | ||
:directory => '', | ||
:authentication => 'basic', | ||
:username => 'your username', | ||
:password => 'your password', | ||
:log_file => 'neography.log', | ||
:log_enabled => false, | ||
:max_threads => 20, | ||
:cypher_path => '/cypher', | ||
:gremlin_path => '/ext/GremlinPlugin/graphdb/execute_script' }) | ||
|
||
Quick initializer (assumes basic authorization if username is given): | ||
|
||
@neo = Neography::Rest.new("http://username:[email protected]:7474/mydirectory") | ||
|
||
|
||
To Use: | ||
Usage: | ||
|
||
@neo = Neography::Rest.new # Inialize using all default parameters | ||
|
||
|
@@ -155,6 +179,7 @@ To Use: | |
@neo.find_node_index(index, query) # advanced query of the node index with the given query | ||
@neo.get_node_auto_index(key, value) # exact query of the node auto index with the given key/value pair | ||
@neo.find_node_auto_index(query) # advanced query of the node auto index with the given query | ||
|
||
@neo.list_relationship_indexes # gives names and query templates for relationship indices | ||
@neo.create_relationship_index(name, "fulltext", provider) # creates a relationship index with "fulltext" option | ||
@neo.create_relationship_auto_index("fulltext", provider) # creates a relationship auto index with "fulltext" option | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,52 @@ | ||
module Neography | ||
class Config | ||
class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password, :parser end | ||
class Config | ||
|
||
attr_accessor :protocol, :server, :port, :directory, | ||
:cypher_path, :gremlin_path, | ||
:log_file, :log_enabled, | ||
:max_threads, | ||
:authentication, :username, :password, | ||
:parser | ||
|
||
def initialize | ||
set_defaults | ||
end | ||
|
||
def to_hash | ||
{ | ||
:protocol => @protocol, | ||
:server => @server, | ||
:port => @port, | ||
:directory => @directory, | ||
:cypher_path => @cypher_path, | ||
:gremlin_path => @gremlin_path, | ||
:log_file => @log_file, | ||
:log_enabled => @log_enabled, | ||
:max_threads => @max_threads, | ||
:authentication => @authentication, | ||
:username => @username, | ||
:password => @password, | ||
:parser => @parser | ||
} | ||
end | ||
|
||
private | ||
|
||
def set_defaults | ||
@protocol = "http://" | ||
@server = "localhost" | ||
@port = 7474 | ||
@directory = "" | ||
@cypher_path = "/cypher" | ||
@gremlin_path = "/ext/GremlinPlugin/graphdb/execute_script" | ||
@log_file = "neography.log" | ||
@log_enabled = false | ||
@max_threads = 20 | ||
@authentication = nil | ||
@username = nil | ||
@password = nil | ||
@parser = {:parser => MultiJsonParser} | ||
end | ||
|
||
@protocol = 'http://' | ||
@server = 'localhost' | ||
@port = 7474 | ||
@directory = '' | ||
@cypher_path = '/cypher' | ||
@gremlin_path = '/ext/GremlinPlugin/graphdb/execute_script' | ||
@log_file = 'neography.log' | ||
@log_enabled = false | ||
@logger = Logger.new(@log_file) if @log_enabled | ||
@max_threads = 20 | ||
@authentication = {} | ||
@username = nil | ||
@password = nil | ||
@parser = {:parser => MultiJsonParser} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'spec_helper' | ||
|
||
describe Neography do | ||
|
||
describe "::configure" do | ||
|
||
it "returns the same configuration" do | ||
Neography.configuration.should == Neography.configuration | ||
end | ||
|
||
it "returns the Config" do | ||
Neography.configuration.should be_a Neography::Config | ||
end | ||
|
||
it "yields the configuration" do | ||
Neography.configure do |config| | ||
config.should == Neography.configuration | ||
end | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'spec_helper' | ||
|
||
module Neography | ||
describe Config do | ||
|
||
subject(:config) | ||
|
||
context "defaults" do | ||
|
||
its(:protocol) { should == 'http://' } | ||
its(:server) { should == 'localhost' } | ||
its(:port) { should == 7474 } | ||
its(:directory) { should == '' } | ||
its(:cypher_path) { should == '/cypher' } | ||
its(:gremlin_path) { should == '/ext/GremlinPlugin/graphdb/execute_script' } | ||
its(:log_file) { should == 'neography.log' } | ||
its(:log_enabled) { should == false } | ||
its(:max_threads) { should == 20 } | ||
its(:authentication) { should == nil } | ||
its(:username) { should == nil } | ||
its(:password) { should == nil } | ||
its(:parser) { should == { :parser => MultiJsonParser } } | ||
|
||
it "has a hash representation" do | ||
expected_hash = { | ||
:protocol => 'http://', | ||
:server => 'localhost', | ||
:port => 7474, | ||
:directory => '', | ||
:cypher_path => '/cypher', | ||
:gremlin_path => '/ext/GremlinPlugin/graphdb/execute_script', | ||
:log_file => 'neography.log', | ||
:log_enabled => false, | ||
:max_threads => 20, | ||
:authentication => nil, | ||
:username => nil, | ||
:password => nil, | ||
:parser => { :parser => MultiJsonParser } | ||
} | ||
config.to_hash.should == expected_hash | ||
end | ||
|
||
end | ||
|
||
end | ||
end |