Skip to content

Commit

Permalink
[REFACTOR] Cleaned up the Index#store method
Browse files Browse the repository at this point in the history
* Restructure the code
* Use `params` Hash to encode URL parameters for elasticsearch
* Prepare solving karmi#256 in a more robust way
  • Loading branch information
karmi authored and NOX73 committed Oct 23, 2012
1 parent 8934d7c commit ab71951
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/tire/index.rb
Expand Up @@ -64,22 +64,24 @@ def settings

def store(*args)
document, options = args
type = get_type_from_document(document)

if options
percolate = options[:percolate]
percolate = "*" if percolate === true
end

id = get_id_from_document(document)
type = get_type_from_document(document)
document = convert_document_to_json(document)

options ||= {}
params = {}

if options[:percolate]
params[:percolate] = options[:percolate]
params[:percolate] = "*" if params[:percolate] === true
end

url = id ? "#{self.url}/#{type}/#{id}" : "#{self.url}/#{type}/"
url += "?percolate=#{percolate}" if percolate
url += "?percolate=#{params[:percolate]}" if params[:percolate]

@response = Configuration.client.post url, document
MultiJson.decode(@response.body)

ensure
curl = %Q|curl -X POST "#{url}" -d '#{document}'|
logged([type, id].join('/'), curl)
Expand Down

0 comments on commit ab71951

Please sign in to comment.