-
Notifications
You must be signed in to change notification settings - Fork 139
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
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 |