From b04c2bc4a19f3a138795f84b1ef8b7df08520004 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Wed, 4 Apr 2012 10:45:46 -0500 Subject: [PATCH] moving crack parser to its own file --- CONTRIBUTORS | 1 + lib/neography.rb | 2 ++ lib/neography/config.rb | 3 ++- lib/neography/crack_parser.rb | 7 +++++++ lib/neography/rest.rb | 14 +++----------- 5 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 lib/neography/crack_parser.rb diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 3789b40..efa0e7c 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -13,3 +13,4 @@ Contributors: * Pablo Fernandez * Nick Reavill * Marcel Sherf +* David Pitman \ No newline at end of file diff --git a/lib/neography.rb b/lib/neography.rb index 84816c0..b279d15 100644 --- a/lib/neography.rb +++ b/lib/neography.rb @@ -16,6 +16,7 @@ def find_and_require_user_defined_code DIRECTIONS = ["incoming", "in", "outgoing", "out", "all", "both"] require 'cgi' +require 'crack' require 'httparty' require 'json' require 'logger' @@ -23,6 +24,7 @@ def find_and_require_user_defined_code require 'os' require 'zip/zipfilesystem' +require 'neography/crack_parser' require 'neography/config' require 'neography/rest' require 'neography/neography' diff --git a/lib/neography/config.rb b/lib/neography/config.rb index efebf0f..fd9d384 100644 --- a/lib/neography/config.rb +++ b/lib/neography/config.rb @@ -1,6 +1,6 @@ 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 end + class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password, :parser end @protocol = 'http://' @server = 'localhost' @@ -15,5 +15,6 @@ class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path @authentication = {} @username = nil @password = nil + @parser = {:parser => CrackParser} end end \ No newline at end of file diff --git a/lib/neography/crack_parser.rb b/lib/neography/crack_parser.rb new file mode 100644 index 0000000..c1c35ed --- /dev/null +++ b/lib/neography/crack_parser.rb @@ -0,0 +1,7 @@ +class CrackParser < HTTParty::Parser + + protected + def json + Crack::JSON.parse(body) + end +end \ No newline at end of file diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 151a95a..4e1f11d 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -3,16 +3,7 @@ module Neography class Rest include HTTParty - class CrackParser < HTTParty::Parser - require 'crack' - - protected - def json - Crack::JSON.parse(body) - end - end - - attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password + attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password, :parser def initialize(options=ENV['NEO4J_URL'] || {}) init = {:protocol => Neography::Config.protocol, @@ -27,6 +18,7 @@ def initialize(options=ENV['NEO4J_URL'] || {}) :authentication => Neography::Config.authentication, :username => Neography::Config.username, :password => Neography::Config.password, + :parser => Neography::Config.parser } unless options.respond_to?(:each_pair) @@ -55,7 +47,7 @@ def initialize(options=ENV['NEO4J_URL'] || {}) @max_threads = init[:max_threads] @authentication = Hash.new @authentication = {"#{init[:authentication]}_auth".to_sym => {:username => init[:username], :password => init[:password]}} unless init[:authentication].empty? - @parser = {:parser => CrackParser} + @parser = init[:parser] end def configure(protocol, server, port, directory)