Skip to content
Browse files

Some additional refactoring in preparation of #27

  • Loading branch information...
1 parent 2591252 commit ccd06bec2f005dbe2165d6b27c7d7847cf2ff989 @moonglum moonglum committed
Showing with 22 additions and 16 deletions.
  1. +22 −16 lib/ashikawa-core/query.rb
View
38 lib/ashikawa-core/query.rb
@@ -143,8 +143,9 @@ def in_range(options={})
# query = Ashikawa::Core::Query.new collection
# query.execute "FOR u IN users LIMIT 2" # => #<Cursor id=33>
def execute(query, options = {})
- options = allowed_options options, [:count, :batch_size]
- post_request "/cursor", options.merge({ query: query })
+ post_request "/cursor",
+ options.merge({ query: query }),
+ [:query, :count, :batch_size]
end
# Test if an AQL query is valid
@@ -206,24 +207,27 @@ def prepare_request_data(request_data)
# Send a simple query to the server
#
# @param [String] path The path for the request
- # @param [Hash] options The options given to the method
- # @param [Array<Symbol>] keys The required keys
- # @return [Hash] The parsed hash for the request
+ # @param [Hash] request_data The data send to the database
+ # @param [Array<Symbol>] keys The keys allowed for this request
+ # @return [String] Server response
# @raise [NoCollectionProvidedException] If you provided a database, no collection
# @api private
- def simple_query_request(path, options, keys)
- options = allowed_options options, keys
- request_data = { collection: collection.name }.merge options
- put_request path, prepare_request_data(request_data)
+ def simple_query_request(path, request_data, allowed_keys)
+ request_data = request_data.merge({ collection: collection.name })
+ put_request path,
+ request_data,
+ allowed_keys << :collection
end
# Perform a put request
#
- # @param [String] path
- # @param [Hash] request_data
- # @return [String] Server response
+ # @param [String] path The path for the request
+ # @param [Hash] request_data The data send to the database
+ # @param [Array] allowed_keys Keys allowed in request_data, if nil: All keys are allowed
+ # @return [Cursor]
# @api private
- def put_request(path, request_data)
+ def put_request(path, request_data, allowed_keys = nil)
+ request_data = allowed_options request_data, allowed_keys unless allowed_keys.nil?
request_data = prepare_request_data request_data
server_response = send_request path, :put => request_data
Cursor.new database, server_response
@@ -231,11 +235,13 @@ def put_request(path, request_data)
# Perform a post request
#
- # @param [String] path
- # @param [Hash] request_data
+ # @param [String] path The path for the request
+ # @param [Hash] request_data The data send to the database
+ # @param [Array] allowed_keys Keys allowed in request_data, if nil: All keys are allowed
# @return [Cursor]
# @api private
- def post_request(path, request_data)
+ def post_request(path, request_data, allowed_keys = nil)
+ request_data = allowed_options request_data, allowed_keys unless allowed_keys.nil?
request_data = prepare_request_data request_data
server_response = send_request path, :post => request_data
Cursor.new database, server_response

0 comments on commit ccd06be

Please sign in to comment.
Something went wrong with that request. Please try again.