Class: Tire::DeleteByQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/tire/delete_by_query.rb

Defined Under Namespace

Classes: DeleteByQueryRequestFailed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(indices = nil, options = {}, &block) ⇒ DeleteByQuery

Returns a new instance of DeleteByQuery.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/tire/delete_by_query.rb', line 7

def initialize(indices=nil, options={}, &block)
  @indices = Array(indices)
  @types   = Array(options[:type]).flatten
  @options = options

  if block_given?
    @query = Search::Query.new
    block.arity < 1 ? @query.instance_eval(&block) : block.call(@query)
  else
    raise "no query given for #{self.class}"
  end
end

Instance Attribute Details

#indicesObject (readonly)

Returns the value of attribute indices.



5
6
7
# File 'lib/tire/delete_by_query.rb', line 5

def indices
  @indices
end

#jsonObject (readonly)

Returns the value of attribute json.



5
6
7
# File 'lib/tire/delete_by_query.rb', line 5

def json
  @json
end

#queryObject (readonly)

Returns the value of attribute query.



5
6
7
# File 'lib/tire/delete_by_query.rb', line 5

def query
  @query
end

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/tire/delete_by_query.rb', line 5

def response
  @response
end

#typesObject (readonly)

Returns the value of attribute types.



5
6
7
# File 'lib/tire/delete_by_query.rb', line 5

def types
  @types
end

Instance Method Details

#performObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tire/delete_by_query.rb', line 20

def perform
  @response = Configuration.client.delete url
  if @response.failure?
    STDERR.puts "[REQUEST FAILED] #{self.to_curl}\n"
    raise DeleteByQueryRequestFailed, @response.to_s
  end
  @json = MultiJson.decode(@response.body)
  true
ensure
  logged
end