lib/architect4r/server.rb in architect4r-0.3.3.1 vs lib/architect4r/server.rb in architect4r-0.3.4
- old
+ new
@@ -37,20 +37,10 @@
def delete
response = Typhoeus::Request.delete(prepend_base_url(url), :params => params)
response.success? ? JSON.parse(response.body) : nil
end
- protected
-
- def prepend_base_url(url)
- if url[0,4] == "http"
- url
- else
- "http://#{configuration.host}:#{configuration.port}#{configuration.path}/db/data#{url}"
- end
- end
-
def node_url(url_or_id)
if url_or_id.is_a?(Hash)
url_or_id['self'].to_s
elsif url_or_id.to_s != '0' and url_or_id.to_i == 0
url_or_id.to_s
@@ -67,11 +57,34 @@
else
prepend_base_url("/relationship/#{url_or_id.to_i}")
end
end
- def convert_if_possible(data)
+ # Build a node or relationship from the hash neo4j returns.
+ def convert_if_possible(object_hash)
+ if klass = object_hash.is_a?(Hash) && object_hash['data']
+ if model_string = object_hash['data']['architect4r_type']
+ data = begin
+ eval("#{model_string}.send(:build_from_database, object_hash)")
+ rescue => ex
+ data
+ end
+ elsif object_hash['self'].match(/node\/\d+$/i)
+ data = GenericNode.send(:build_from_database, object_hash)
+ end
+ end
data
+ end
+
+
+ protected
+
+ def prepend_base_url(url)
+ if url[0,4] == "http"
+ url
+ else
+ "http://#{configuration.host}:#{configuration.port}#{configuration.path}/db/data#{url}"
+ end
end
end
\ No newline at end of file