Skip to content

Commit

Permalink
moving crack parser to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Apr 4, 2012
1 parent 1d14860 commit b04c2bc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Contributors:
* Pablo Fernandez
* Nick Reavill
* Marcel Sherf
* David Pitman
2 changes: 2 additions & 0 deletions lib/neography.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ def find_and_require_user_defined_code
DIRECTIONS = ["incoming", "in", "outgoing", "out", "all", "both"]

require 'cgi'
require 'crack'
require 'httparty'
require 'json'
require 'logger'
require 'ostruct'
require 'os'
require 'zip/zipfilesystem'

require 'neography/crack_parser'
require 'neography/config'
require 'neography/rest'
require 'neography/neography'
Expand Down
3 changes: 2 additions & 1 deletion lib/neography/config.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -15,5 +15,6 @@ class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path
@authentication = {}
@username = nil
@password = nil
@parser = {:parser => CrackParser}
end
end
7 changes: 7 additions & 0 deletions lib/neography/crack_parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CrackParser < HTTParty::Parser

protected
def json
Crack::JSON.parse(body)
end
end
14 changes: 3 additions & 11 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b04c2bc

Please sign in to comment.