Permalink
Browse files

removed some code smells

  • Loading branch information...
1 parent bf06b93 commit 4dab2ad47a6dda4e46525568e05234785c564216 @phifty committed Mar 30, 2010
@@ -2,6 +2,8 @@
module AllegroGraph
+ # The Catalog class wrap the corresponding resource on the AllegroGraph server. A catalog can hold
+ # many repositories.
class Catalog
attr_reader :server
@@ -6,6 +6,8 @@
module AllegroGraph
+ # The Federation class wrap the corresponding resource on the AllegroGraph server. A federation is a collection
+ # of many repositories that acts like a single one. Only read access is allowed.
class Federation
attr_reader :server
@@ -4,6 +4,7 @@ module AllegroGraph
module Proxy
+ # The Geometric class acts as proxy to the geo-functions of the AllegroGraph server.
class Geometric
attr_reader :resource
@@ -3,6 +3,7 @@ module AllegroGraph
module Proxy
+ # The Mapping class acts as proxy to the data type mapping functions of the AllegroGraph server.
class Mapping
attr_reader :resource
@@ -3,6 +3,7 @@ module AllegroGraph
module Proxy
+ # The Query class acts as proxy that bypasses SparQL and Prolog queries to the AllegroGraph server.
class Query
LANGUAGES = [ :sparql, :prolog ].freeze unless defined?(LANGUAGES)
@@ -21,8 +22,9 @@ def path
end
def language=(value)
- raise NotImplementedError, "query langauge [#{value}] is not implemented" unless LANGUAGES.include?(value.to_sym)
- @language = value.to_sym
+ value = value.to_sym
+ raise NotImplementedError, "query langauge [#{value}] is not implemented" unless LANGUAGES.include?(value)
+ @language = value
end
def perform(query)
@@ -4,6 +4,8 @@ module AllegroGraph
module Proxy
+ # The Statement class acts as proxy to functions that add, remove or find statements
+ # in the AllegroGraph data store.
class Statements
attr_reader :resource
@@ -7,6 +7,8 @@
module AllegroGraph
+ # The Repository class wrap the corresponding resource on the AllegroGraph server. A repository acts as a scope for
+ # statements. Simple management methods are provided.
class Repository
attr_reader :server
@@ -74,14 +76,18 @@ def size
end
def transaction(&block)
- session = Session.create self
+ self.class.transaction self, &block
+ end
+
+ def self.transaction(repository, &block)
+ session = Session.create repository
begin
session.instance_eval &block
rescue Object => error
session.rollback
raise error
end
- session.commit
+ session.commit
end
end
@@ -6,6 +6,7 @@
module AllegroGraph
+ # The Session class wrap the corresponding resource on the AllegroGraph server.
class Session
attr_reader :url
@@ -50,7 +51,8 @@ def self.create(repository)
url = repository.request :post, repository.path + "/session", :expected_status_code => 200
url.sub! /^"/, ""
url.sub! /"$/, ""
- new :url => url, :username => repository.server.username, :password => repository.server.password
+ server = repository.server
+ new :url => url, :username => server.username, :password => server.password
end
private
@@ -62,11 +62,8 @@ def serialize_parameters
def quote_parameters
@quoted_parameters = { }
@parameters.each do |key, value|
- if value.is_a?(Array)
- @quoted_parameters[ CGI.escape("#{key}") ] = value.map{ |element| CGI.escape element }
- else
- @quoted_parameters[ CGI.escape("#{key}") ] = CGI.escape value
- end
+ quoted_key = CGI.escape(key.to_s)
+ @quoted_parameters[quoted_key] = value.is_a?(Array) ? value.map{ |element| CGI.escape element } : CGI.escape(value)
end
end
@@ -93,6 +90,7 @@ def self.request(http_method, url, options = { })
end
+ # Extended transport layer for http transfers. Basic authorization and JSON transfers are supported.
class ExtendedTransport < Transport
# The UnexpectedStatusCodeError is raised if the :expected_status_code option is given to
@@ -159,9 +157,10 @@ def check_status_code
end
def parse_response
- @response = @response.body.nil? ? nil : JSON.parse(@response.body)
+ body = @response.body
+ @response = body.nil? ? nil : JSON.parse(body)
rescue JSON::ParserError
- @response = @response.body.to_s
+ @response = body.to_s
end
end

0 comments on commit 4dab2ad

Please sign in to comment.