elastictastic 0.10.7 → 0.10.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -110,9 +110,9 @@ module Elastictastic
110
110
  # in the default index.
111
111
  #
112
112
 
113
- delegate :find, :destroy, :destroy_all, :sync_mapping, :inspect,
114
- :find_each, :find_in_batches, :first, :count, :empty?, :any?,
115
- :all, :query, :filter, :from, :size, :sort, :highlight, :fields,
113
+ delegate :find, :destroy_all, :sync_mapping, :inspect, :find_each,
114
+ :find_in_batches, :first, :count, :empty?, :any?, :all,
115
+ :query, :filter, :from, :size, :sort, :highlight, :fields,
116
116
  :script_fields, :preference, :facets, :routing,
117
117
  :to => :current_scope
118
118
 
@@ -21,7 +21,7 @@ module Elastictastic
21
21
  add(
22
22
  instance.index,
23
23
  instance.id,
24
- { 'create' => bulk_identifier_for_instance(instance) },
24
+ { 'create' => bulk_identifier(instance) },
25
25
  instance.elasticsearch_doc
26
26
  ) do |response|
27
27
  if response['create']['error']
@@ -41,7 +41,7 @@ module Elastictastic
41
41
  add(
42
42
  instance.index,
43
43
  instance.id,
44
- { 'index' => bulk_identifier_for_instance(instance) },
44
+ { 'index' => bulk_identifier(instance) },
45
45
  instance.elasticsearch_doc
46
46
  ) do |response|
47
47
  if response['index']['error']
@@ -56,7 +56,7 @@ module Elastictastic
56
56
  def destroy(instance, &block)
57
57
  block ||= DEFAULT_HANDLER
58
58
  instance.pending_destroy!
59
- add(instance.index, instance.id, :delete => bulk_identifier_for_instance(instance)) do |response|
59
+ add(instance.index, instance.id, :delete => bulk_identifier(instance)) do |response|
60
60
  if response['delete']['error']
61
61
  block.call(ServerError[response['delete']['error']])
62
62
  else
@@ -67,13 +67,6 @@ module Elastictastic
67
67
  end
68
68
  end
69
69
 
70
- def destroy!(index, type, id, routing, parent)
71
- add(
72
- index, id,
73
- :delete => bulk_identifier(index, type, id, routing, parent, nil)
74
- )
75
- end
76
-
77
70
  def flush
78
71
  return if @operations.empty?
79
72
 
@@ -99,23 +92,13 @@ module Elastictastic
99
92
 
100
93
  private
101
94
 
102
- def bulk_identifier_for_instance(instance)
103
- bulk_identifier(
104
- instance.index,
105
- instance.class.type,
106
- instance.id,
107
- instance.class.route(instance),
108
- instance._parent_id,
109
- instance.version
110
- )
111
- end
112
-
113
- def bulk_identifier(index, type, id, routing, parent_id, version)
114
- identifier = { :_index => index.name, :_type => type }
115
- identifier['_id'] = id if id
116
- identifier['_version'] = version if version
95
+ def bulk_identifier(instance)
96
+ identifier = { :_index => instance.index.name, :_type => instance.class.type }
97
+ identifier['_id'] = instance.id if instance.id
98
+ identifier['_version'] = instance.version if instance.version
99
+ routing = instance.class.route(instance)
117
100
  identifier['_routing'] = routing.to_s if routing
118
- identifier['parent'] = parent_id if parent_id
101
+ identifier['parent'] = instance._parent_id if instance._parent_id
119
102
  identifier
120
103
  end
121
104
 
@@ -16,7 +16,7 @@ module Elastictastic
16
16
  doc.class.type,
17
17
  doc.id,
18
18
  doc.elasticsearch_doc,
19
- params_for_doc(doc)
19
+ params_for(doc)
20
20
  )
21
21
  rescue => e
22
22
  return block.call(e)
@@ -35,7 +35,7 @@ module Elastictastic
35
35
  doc.class.type,
36
36
  doc.id,
37
37
  doc.elasticsearch_doc,
38
- params_for_doc(doc)
38
+ params_for(doc)
39
39
  )
40
40
  rescue => e
41
41
  return block.call(e)
@@ -52,7 +52,7 @@ module Elastictastic
52
52
  doc.index.name,
53
53
  doc.class.type,
54
54
  doc.id,
55
- params_for_doc(doc)
55
+ params_for(doc)
56
56
  )
57
57
  rescue => e
58
58
  return block.call(e)
@@ -62,32 +62,15 @@ module Elastictastic
62
62
  response['found']
63
63
  end
64
64
 
65
- def destroy!(index, type, id, routing, parent)
66
- response = Elastictastic.client.delete(
67
- index,
68
- type,
69
- id,
70
- params_for(routing, parent, nil)
71
- )
72
- response['found']
73
- end
74
-
75
65
  private
76
66
 
77
- def params_for_doc(doc)
78
- params_for(
79
- doc.class.route(doc),
80
- doc._parent_id,
81
- doc.version
82
- )
83
- end
84
-
85
- def params_for(routing, parent_id, version)
67
+ def params_for(doc)
86
68
  {}.tap do |params|
87
69
  params[:refresh] = true if Elastictastic.config.auto_refresh
88
- params[:parent] = parent_id if parent_id
89
- params[:version] = version if version
90
- params[:routing] = routing.to_s if routing
70
+ params[:parent] = doc._parent_id if doc._parent_id
71
+ params[:version] = doc.version if doc.version
72
+ routing = doc.class.route(doc)
73
+ params[:routing] = routing if routing
91
74
  end
92
75
  end
93
76
  end
@@ -3,7 +3,7 @@ module Elastictastic
3
3
  def save(options = {}, &block)
4
4
  persisted? ? update(options, &block) : create(options, &block)
5
5
  end
6
-
6
+
7
7
  def destroy(options = {}, &block)
8
8
  if persisted?
9
9
  Elastictastic.persister.destroy(self, &block)
@@ -140,21 +140,6 @@ module Elastictastic
140
140
  )
141
141
  end
142
142
 
143
- #
144
- # Destroy one or more documents by ID, without reading them first
145
- #
146
- def destroy(*ids)
147
- ids.each do |id|
148
- ::Elastictastic.persister.destroy!(
149
- @index,
150
- @clazz.type,
151
- id,
152
- @routing,
153
- (@parent.id if @parent)
154
- )
155
- end
156
- end
157
-
158
143
  #
159
144
  # Destroy all documents in this index.
160
145
  #
@@ -246,9 +231,7 @@ module Elastictastic
246
231
  end
247
232
 
248
233
  def inspect
249
- inspected = "#{@clazz.name}:#{@index.name}"
250
- inspected << ::Elastictastic.json_encode(@search.params) unless @search.params.empty?
251
- inspected
234
+ self.entries.inspect
252
235
  end
253
236
 
254
237
  #
@@ -1,3 +1,3 @@
1
1
  module Elastictastic
2
- VERSION = '0.10.7'
2
+ VERSION = '0.10.8'
3
3
  end
@@ -200,21 +200,6 @@ describe Elastictastic::BulkPersistenceStrategy do
200
200
  end
201
201
  end
202
202
 
203
- describe 'destroy!' do
204
- before do
205
- stub_es_bulk(
206
- 'delete' => { '_index' => 'default', '_type' => 'post', '_id' => '123', '_version' => 2, 'ok' => true }
207
- )
208
- Elastictastic.bulk { Post.in_index('my_index').destroy('123') }
209
- end
210
-
211
- it 'should send destroy' do
212
- bulk_requests.should == [
213
- { 'delete' => { '_index' => 'my_index', '_type' => 'post', '_id' => '123' }}
214
- ]
215
- end
216
- end
217
-
218
203
  shared_examples_for 'block with error' do
219
204
  it 'should not run bulk operation' do
220
205
  error_proc.call rescue nil
@@ -194,45 +194,6 @@ describe Elastictastic::Document do
194
194
  end
195
195
  end # describe '#save'
196
196
 
197
- describe '::destroy' do
198
- context 'with default index and no routing' do
199
- before do
200
- stub_es_destroy('default', 'post', '123')
201
- Post.destroy('123')
202
- end
203
-
204
- it 'should send DELETE request' do
205
- last_request.method.should == 'DELETE'
206
- end
207
-
208
- it 'should send request to document resource path' do
209
- last_request.path.should == '/default/post/123'
210
- end
211
- end # context 'existing persisted object'
212
-
213
- context 'with routing' do
214
- before do
215
- stub_es_destroy('default', 'photo', 'abc')
216
- Photo.routing('123').destroy('abc')
217
- end
218
-
219
- it 'should include routing param' do
220
- last_request_uri.query.split('&').should include('routing=123')
221
- end
222
- end
223
-
224
- context 'on specified index' do
225
- before do
226
- stub_es_destroy('my_index', 'post', '123')
227
- Post.in_index('my_index').destroy('123')
228
- end
229
-
230
- it 'should send request to specified index resource' do
231
- last_request.path.should == '/my_index/post/123'
232
- end
233
- end
234
- end # describe '#destroy'
235
-
236
197
  describe '#destroy' do
237
198
  context 'existing persisted object' do
238
199
  let(:post) do
@@ -81,12 +81,6 @@ describe Elastictastic::ParentChild do
81
81
  post.destroy
82
82
  URI.parse(FakeWeb.last_request.path).query.split('&').should include("parent=#{blog.id}")
83
83
  end
84
-
85
- it 'should pass parent on ::delete' do
86
- stub_es_destroy('default', 'post', '123')
87
- blog.posts.destroy('123')
88
- URI.parse(FakeWeb.last_request.path).query.split('&').should include("parent=#{blog.id}")
89
- end
90
84
  end
91
85
 
92
86
  describe 'bulk persistence' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastictastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.7
4
+ version: 0.10.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-12-19 00:00:00.000000000 Z
14
+ date: 2012-12-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
18
- requirement: !ruby/object:Gem::Requirement
18
+ requirement: &8804860 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,15 +23,10 @@ dependencies:
23
23
  version: '3.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
- requirements:
29
- - - ~>
30
- - !ruby/object:Gem::Version
31
- version: '3.0'
26
+ version_requirements: *8804860
32
27
  - !ruby/object:Gem::Dependency
33
28
  name: activemodel
34
- requirement: !ruby/object:Gem::Requirement
29
+ requirement: &8804300 !ruby/object:Gem::Requirement
35
30
  none: false
36
31
  requirements:
37
32
  - - ~>
@@ -39,15 +34,10 @@ dependencies:
39
34
  version: '3.0'
40
35
  type: :runtime
41
36
  prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
- requirements:
45
- - - ~>
46
- - !ruby/object:Gem::Version
47
- version: '3.0'
37
+ version_requirements: *8804300
48
38
  - !ruby/object:Gem::Dependency
49
39
  name: hashie
50
- requirement: !ruby/object:Gem::Requirement
40
+ requirement: &8803880 !ruby/object:Gem::Requirement
51
41
  none: false
52
42
  requirements:
53
43
  - - ! '>='
@@ -55,15 +45,10 @@ dependencies:
55
45
  version: '0'
56
46
  type: :runtime
57
47
  prerelease: false
58
- version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
- requirements:
61
- - - ! '>='
62
- - !ruby/object:Gem::Version
63
- version: '0'
48
+ version_requirements: *8803880
64
49
  - !ruby/object:Gem::Dependency
65
50
  name: i18n
66
- requirement: !ruby/object:Gem::Requirement
51
+ requirement: &8803320 !ruby/object:Gem::Requirement
67
52
  none: false
68
53
  requirements:
69
54
  - - ! '>='
@@ -71,15 +56,10 @@ dependencies:
71
56
  version: '0'
72
57
  type: :runtime
73
58
  prerelease: false
74
- version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
- requirements:
77
- - - ! '>='
78
- - !ruby/object:Gem::Version
79
- version: '0'
59
+ version_requirements: *8803320
80
60
  - !ruby/object:Gem::Dependency
81
61
  name: multi_json
82
- requirement: !ruby/object:Gem::Requirement
62
+ requirement: &8802880 !ruby/object:Gem::Requirement
83
63
  none: false
84
64
  requirements:
85
65
  - - ! '>='
@@ -87,15 +67,10 @@ dependencies:
87
67
  version: '0'
88
68
  type: :runtime
89
69
  prerelease: false
90
- version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
- requirements:
93
- - - ! '>='
94
- - !ruby/object:Gem::Version
95
- version: '0'
70
+ version_requirements: *8802880
96
71
  - !ruby/object:Gem::Dependency
97
72
  name: rspec
98
- requirement: !ruby/object:Gem::Requirement
73
+ requirement: &8802260 !ruby/object:Gem::Requirement
99
74
  none: false
100
75
  requirements:
101
76
  - - ~>
@@ -103,15 +78,10 @@ dependencies:
103
78
  version: '2.0'
104
79
  type: :development
105
80
  prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
- requirements:
109
- - - ~>
110
- - !ruby/object:Gem::Version
111
- version: '2.0'
81
+ version_requirements: *8802260
112
82
  - !ruby/object:Gem::Dependency
113
83
  name: fakeweb
114
- requirement: !ruby/object:Gem::Requirement
84
+ requirement: &8801580 !ruby/object:Gem::Requirement
115
85
  none: false
116
86
  requirements:
117
87
  - - ~>
@@ -119,15 +89,10 @@ dependencies:
119
89
  version: '1.3'
120
90
  type: :development
121
91
  prerelease: false
122
- version_requirements: !ruby/object:Gem::Requirement
123
- none: false
124
- requirements:
125
- - - ~>
126
- - !ruby/object:Gem::Version
127
- version: '1.3'
92
+ version_requirements: *8801580
128
93
  - !ruby/object:Gem::Dependency
129
94
  name: yard
130
- requirement: !ruby/object:Gem::Requirement
95
+ requirement: &8800940 !ruby/object:Gem::Requirement
131
96
  none: false
132
97
  requirements:
133
98
  - - ~>
@@ -135,12 +100,7 @@ dependencies:
135
100
  version: '0.6'
136
101
  type: :development
137
102
  prerelease: false
138
- version_requirements: !ruby/object:Gem::Requirement
139
- none: false
140
- requirements:
141
- - - ~>
142
- - !ruby/object:Gem::Version
143
- version: '0.6'
103
+ version_requirements: *8800940
144
104
  description: ! 'Elastictastic is an object-document mapper and lightweight API adapter
145
105
  for
146
106
 
@@ -157,74 +117,74 @@ extensions: []
157
117
  extra_rdoc_files:
158
118
  - README.md
159
119
  files:
160
- - lib/elastictastic.rb
161
- - lib/elastictastic/optimistic_locking.rb
162
- - lib/elastictastic/server_error.rb
163
- - lib/elastictastic/document.rb
164
- - lib/elastictastic/nested_document.rb
165
- - lib/elastictastic/child_collection_proxy.rb
166
- - lib/elastictastic/mass_assignment_security.rb
167
- - lib/elastictastic/scope_builder.rb
168
- - lib/elastictastic/util.rb
169
- - lib/elastictastic/index.rb
170
- - lib/elastictastic/bulk_persistence_strategy.rb
171
- - lib/elastictastic/basic_document.rb
172
- - lib/elastictastic/thrift/rest.rb
173
- - lib/elastictastic/thrift/constants.rb
174
- - lib/elastictastic/thrift/types.rb
175
120
  - lib/elastictastic/multi_search.rb
176
- - lib/elastictastic/association.rb
177
- - lib/elastictastic/adapter.rb
178
- - lib/elastictastic/discrete_persistence_strategy.rb
179
- - lib/elastictastic/callbacks.rb
121
+ - lib/elastictastic/transport_methods.rb
122
+ - lib/elastictastic/basic_document.rb
180
123
  - lib/elastictastic/observer.rb
124
+ - lib/elastictastic/middleware.rb
125
+ - lib/elastictastic/child_collection_proxy.rb
126
+ - lib/elastictastic/dirty.rb
127
+ - lib/elastictastic/rotor.rb
128
+ - lib/elastictastic/errors.rb
129
+ - lib/elastictastic/scope.rb
130
+ - lib/elastictastic/discrete_persistence_strategy.rb
131
+ - lib/elastictastic/parent_child.rb
132
+ - lib/elastictastic/adapter.rb
181
133
  - lib/elastictastic/embedded_document.rb
182
- - lib/elastictastic/test_helpers.rb
183
- - lib/elastictastic/thrift_adapter.rb
184
- - lib/elastictastic/version.rb
185
- - lib/elastictastic/validations.rb
186
- - lib/elastictastic/persistence.rb
187
- - lib/elastictastic/railtie.rb
134
+ - lib/elastictastic/new_relic_instrumentation.rb
135
+ - lib/elastictastic/optimistic_locking.rb
136
+ - lib/elastictastic/callbacks.rb
137
+ - lib/elastictastic/util.rb
138
+ - lib/elastictastic/nested_document.rb
139
+ - lib/elastictastic/association.rb
188
140
  - lib/elastictastic/client.rb
141
+ - lib/elastictastic/document.rb
189
142
  - lib/elastictastic/properties.rb
190
- - lib/elastictastic/rotor.rb
143
+ - lib/elastictastic/test_helpers.rb
144
+ - lib/elastictastic/search.rb
145
+ - lib/elastictastic/thrift/types.rb
146
+ - lib/elastictastic/thrift/rest.rb
147
+ - lib/elastictastic/thrift/constants.rb
191
148
  - lib/elastictastic/multi_get.rb
192
- - lib/elastictastic/parent_child.rb
149
+ - lib/elastictastic/mass_assignment_security.rb
150
+ - lib/elastictastic/server_error.rb
151
+ - lib/elastictastic/version.rb
152
+ - lib/elastictastic/scope_builder.rb
153
+ - lib/elastictastic/persistence.rb
154
+ - lib/elastictastic/observing.rb
155
+ - lib/elastictastic/index.rb
156
+ - lib/elastictastic/validations.rb
157
+ - lib/elastictastic/bulk_persistence_strategy.rb
193
158
  - lib/elastictastic/field.rb
194
- - lib/elastictastic/scope.rb
195
159
  - lib/elastictastic/scoped.rb
196
- - lib/elastictastic/new_relic_instrumentation.rb
197
- - lib/elastictastic/search.rb
198
- - lib/elastictastic/transport_methods.rb
199
- - lib/elastictastic/middleware.rb
160
+ - lib/elastictastic/thrift_adapter.rb
161
+ - lib/elastictastic/railtie.rb
200
162
  - lib/elastictastic/configuration.rb
201
- - lib/elastictastic/dirty.rb
202
- - lib/elastictastic/errors.rb
203
- - lib/elastictastic/observing.rb
163
+ - lib/elastictastic.rb
164
+ - spec/models/photo.rb
165
+ - spec/models/post.rb
166
+ - spec/models/blog.rb
167
+ - spec/models/author.rb
168
+ - spec/models/post_observer.rb
169
+ - spec/models/comment.rb
204
170
  - spec/environment.rb
171
+ - spec/examples/callbacks_spec.rb
172
+ - spec/examples/mass_assignment_security_spec.rb
173
+ - spec/examples/rotor_spec.rb
174
+ - spec/examples/middleware_spec.rb
175
+ - spec/examples/optimistic_locking_spec.rb
176
+ - spec/examples/parent_child_spec.rb
177
+ - spec/examples/scope_spec.rb
205
178
  - spec/examples/bulk_persistence_strategy_spec.rb
206
- - spec/examples/document_spec.rb
207
179
  - spec/examples/properties_spec.rb
208
- - spec/examples/validation_spec.rb
209
- - spec/examples/optimistic_locking_spec.rb
210
- - spec/examples/middleware_spec.rb
211
- - spec/examples/mass_assignment_security_spec.rb
212
- - spec/examples/dirty_spec.rb
213
- - spec/examples/spec_helper.rb
214
180
  - spec/examples/multi_search_spec.rb
215
- - spec/examples/rotor_spec.rb
216
- - spec/examples/callbacks_spec.rb
217
181
  - spec/examples/multi_get_spec.rb
218
- - spec/examples/scope_spec.rb
219
- - spec/examples/parent_child_spec.rb
220
- - spec/examples/observing_spec.rb
221
182
  - spec/examples/search_spec.rb
222
- - spec/models/post_observer.rb
223
- - spec/models/author.rb
224
- - spec/models/blog.rb
225
- - spec/models/post.rb
226
- - spec/models/photo.rb
227
- - spec/models/comment.rb
183
+ - spec/examples/document_spec.rb
184
+ - spec/examples/dirty_spec.rb
185
+ - spec/examples/validation_spec.rb
186
+ - spec/examples/observing_spec.rb
187
+ - spec/examples/spec_helper.rb
228
188
  - spec/support/fakeweb_request_history.rb
229
189
  - README.md
230
190
  - LICENSE
@@ -250,26 +210,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
210
  requirements:
251
211
  - ElasticSearch
252
212
  rubyforge_project:
253
- rubygems_version: 1.8.24
213
+ rubygems_version: 1.8.15
254
214
  signing_key:
255
215
  specification_version: 3
256
216
  summary: Object-document mapper for ElasticSearch
257
217
  test_files:
218
+ - spec/examples/callbacks_spec.rb
219
+ - spec/examples/mass_assignment_security_spec.rb
220
+ - spec/examples/rotor_spec.rb
221
+ - spec/examples/middleware_spec.rb
222
+ - spec/examples/optimistic_locking_spec.rb
223
+ - spec/examples/parent_child_spec.rb
224
+ - spec/examples/scope_spec.rb
258
225
  - spec/examples/bulk_persistence_strategy_spec.rb
259
- - spec/examples/document_spec.rb
260
226
  - spec/examples/properties_spec.rb
261
- - spec/examples/validation_spec.rb
262
- - spec/examples/optimistic_locking_spec.rb
263
- - spec/examples/middleware_spec.rb
264
- - spec/examples/mass_assignment_security_spec.rb
265
- - spec/examples/dirty_spec.rb
266
- - spec/examples/spec_helper.rb
267
227
  - spec/examples/multi_search_spec.rb
268
- - spec/examples/rotor_spec.rb
269
- - spec/examples/callbacks_spec.rb
270
228
  - spec/examples/multi_get_spec.rb
271
- - spec/examples/scope_spec.rb
272
- - spec/examples/parent_child_spec.rb
273
- - spec/examples/observing_spec.rb
274
229
  - spec/examples/search_spec.rb
230
+ - spec/examples/document_spec.rb
231
+ - spec/examples/dirty_spec.rb
232
+ - spec/examples/validation_spec.rb
233
+ - spec/examples/observing_spec.rb
234
+ - spec/examples/spec_helper.rb
275
235
  has_rdoc: true