elastic_adapter 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +3 -0
  3. data/.rubocop.yml +8 -0
  4. data/.ruby.yml +261 -0
  5. data/.travis.yml +6 -0
  6. data/README.md +87 -8
  7. data/elastic_adapter.gemspec +1 -0
  8. data/examples/basic_usage.rb +164 -0
  9. data/lib/elastic_adapter/decoration/count_response.rb +0 -2
  10. data/lib/elastic_adapter/decoration/decorator.rb +2 -4
  11. data/lib/elastic_adapter/decoration/response_decorator_factory.rb +3 -6
  12. data/lib/elastic_adapter/decoration/search_response.rb +0 -2
  13. data/lib/elastic_adapter/decoration/suggestion_response.rb +0 -1
  14. data/lib/elastic_adapter/decoration/validation_response.rb +0 -1
  15. data/lib/elastic_adapter/document_type.rb +12 -2
  16. data/lib/elastic_adapter/index.rb +103 -10
  17. data/lib/elastic_adapter/response.rb +2 -1
  18. data/lib/elastic_adapter/version.rb +1 -1
  19. data/spec/cassettes/ElasticAdapter_Index/_count/empty_index/is_a_response.yml +1 -1
  20. data/spec/cassettes/ElasticAdapter_Index/_count/empty_index/{returs_the_amount_of_all_documents.yml → returns_the_amount_of_all_documents.yml} +1 -1
  21. data/spec/cassettes/ElasticAdapter_Index/_count/empty_index.yml +57 -0
  22. data/spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/is_a_response.yml +1 -1
  23. data/spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/returns_1.yml +1 -1
  24. data/spec/cassettes/ElasticAdapter_Index/_count/not_empty_index.yml +84 -0
  25. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present/response/has_an_exception.yml +2 -2
  26. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present/response/is_a_Response.yml +2 -2
  27. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present.yml +57 -0
  28. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response/has_no_exception.yml +2 -29
  29. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response/is_a_Response.yml +2 -29
  30. data/spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response.yml +30 -0
  31. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_not_present/repsonse/has_an_exception.yml +1 -1
  32. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_not_present/repsonse/is_a_Response.yml +1 -1
  33. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/has_no_exception.yml +1 -28
  34. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/has_no_exceptionElasticAdapter_Index/_delete_index/index_present/repsonse.yml +30 -0
  35. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/is_a_Response.yml +1 -28
  36. data/spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/is_a_ResponseElasticAdapter_Index/_delete_index/index_present/repsonse.yml +30 -0
  37. data/spec/cassettes/ElasticAdapter_Index/_get/document_exists/response/contains_the_document.yml +1 -1
  38. data/spec/cassettes/ElasticAdapter_Index/_get/document_exists.yml +84 -0
  39. data/spec/cassettes/ElasticAdapter_Index/_index/existing_document/doesn_t_change_the_document_count.yml +3 -3
  40. data/spec/cassettes/ElasticAdapter_Index/_index/existing_document/invokes_to_hash_on_the_document.yml +1 -1
  41. data/spec/cassettes/ElasticAdapter_Index/_index/existing_document/updates_the_document.yml +1 -1
  42. data/spec/cassettes/ElasticAdapter_Index/_index/existing_document.yml +84 -0
  43. data/spec/cassettes/ElasticAdapter_Index/_index/new_document/indexes_a_document.yml +3 -3
  44. data/spec/cassettes/ElasticAdapter_Index/_index/new_document/invokes_to_hash_on_the_document.yml +2 -2
  45. data/spec/cassettes/ElasticAdapter_Index/_index/new_document.yml +57 -0
  46. data/spec/cassettes/ElasticAdapter_Index/_search/match_all/returns_all_documents.yml +3 -3
  47. data/spec/cassettes/ElasticAdapter_Index/_search/zoo/returns_one_document.yml +3 -3
  48. data/spec/cassettes/ElasticAdapter_Index/_search/zoo/returns_the_wanted_document.yml +3 -3
  49. data/spec/cassettes/ElasticAdapter_Index/_search.yml +111 -0
  50. data/spec/cassettes/ElasticAdapter_Index/_suggest/query_ba_/returns_bar.yml +2 -2
  51. data/spec/cassettes/ElasticAdapter_Index/_suggest/query_ba_/returns_one_result.yml +2 -2
  52. data/spec/cassettes/ElasticAdapter_Index/_suggest.yml +111 -0
  53. data/spec/cassettes/ElasticAdapter_Index/_validate/invalid_query/is_a_response.yml +4 -3
  54. data/spec/cassettes/ElasticAdapter_Index/_validate/invalid_query/is_false.yml +1 -1
  55. data/spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_a_response.yml +3 -3
  56. data/spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_true.yml +1 -1
  57. data/spec/cassettes/ElasticAdapter_Index/_validate.yml +57 -0
  58. data/spec/index/count_spec.rb +46 -0
  59. data/spec/index/create_index_spec.rb +39 -0
  60. data/spec/index/delete_index_spec.rb +29 -0
  61. data/spec/index/get_spec.rb +29 -0
  62. data/spec/index/index_spec.rb +60 -0
  63. data/spec/index/search_spec.rb +37 -0
  64. data/spec/index/shared_context.rb +37 -0
  65. data/spec/index/shared_examples.rb +19 -0
  66. data/spec/index/suggest_spec.rb +44 -0
  67. data/spec/index/unit_spec.rb +69 -0
  68. data/spec/index/validate_spec.rb +55 -0
  69. data/spec/spec_helper.rb +6 -1
  70. data/spec/support/index_helper.rb +78 -0
  71. metadata +72 -7
  72. data/spec/index_spec.rb +0 -458
data/spec/spec_helper.rb CHANGED
@@ -2,13 +2,16 @@ require "elastic_adapter"
2
2
  require "rake"
3
3
  require "webmock/rspec"
4
4
  require "vcr"
5
+ require "support/index_helper"
6
+ require "codeclimate-test-reporter"
7
+
8
+ CodeClimate::TestReporter.start
5
9
 
6
10
  VCR.configure do |config|
7
11
  config.cassette_library_dir = 'spec/cassettes'
8
12
  config.hook_into :webmock
9
13
  config.default_cassette_options = { record: :new_episodes }
10
14
  config.configure_rspec_metadata!
11
- config.allow_http_connections_when_no_cassette = true
12
15
  end
13
16
 
14
17
  # This file was generated by the `rspec --init` command. Conventionally, all
@@ -51,6 +54,8 @@ RSpec.configure do |config|
51
54
  mocks.verify_partial_doubles = true
52
55
  end
53
56
 
57
+ config.include IndexHelper
58
+
54
59
  # The settings below are suggested to provide a good initial experience
55
60
  # with RSpec, but feel free to customize to your heart's content.
56
61
  =begin
@@ -0,0 +1,78 @@
1
+ module IndexHelper
2
+ WAIT_TIME = 3
3
+
4
+ def test_index(name = "test_index", options = {})
5
+ params = {
6
+ name: name,
7
+ url: "http://localhost:9200",
8
+ log: true,
9
+ settings: {},
10
+ document_type: OpenStruct.new(
11
+ name: "test_doc",
12
+ mappings: {
13
+ test_doc: {
14
+ properties: {
15
+ foo: { type: "string" },
16
+ foo_suggest: { type: "completion" }
17
+ }
18
+ }
19
+ }
20
+ )
21
+ }.merge(options)
22
+
23
+ ElasticAdapter::Index.new(params)
24
+ end
25
+
26
+ def create_test_index(options = {})
27
+ prefix = options.fetch(:prefix, "")
28
+ cassette_name = prefix + vcr_cassette_name_for(self.class.metadata)
29
+
30
+ VCR.use_cassette cassette_name do
31
+ test_index("test_index", options).create_index.tap { sleep WAIT_TIME if ENV["RECORDING"] }
32
+ end
33
+ end
34
+
35
+ def delete_test_index(options = {})
36
+ prefix = options.fetch(:prefix, "")
37
+ cassette_name = prefix + vcr_cassette_name_for(self.class.metadata)
38
+
39
+ VCR.use_cassette cassette_name do
40
+ test_index("test_index", options).delete_index # .tap { sleep 1 if ENV["RECORDING"] }
41
+ end
42
+ end
43
+
44
+ def index_documents(documents, options = {})
45
+ prefix = options.fetch(:prefix, "")
46
+ cassette_name = prefix + vcr_cassette_name_for(self.class.metadata)
47
+
48
+ documents = [documents] unless documents.is_a? Array
49
+
50
+ VCR.use_cassette cassette_name do
51
+ documents.each do |document|
52
+ test_index("test_index", options).index(document).tap { sleep WAIT_TIME if ENV["RECORDING"] }
53
+ end
54
+ end
55
+ end
56
+
57
+ def wait(time = WAIT_TIME)
58
+ sleep time if ENV["RECORDING"]
59
+ end
60
+
61
+ # Taken from https://github.com/vcr/vcr/blob/bbf43f2cd4cc18b450fb37bcb32aa9d427d4235e/lib/vcr/test_frameworks/rspec.rb
62
+ #
63
+ def vcr_cassette_name_for(metadata)
64
+ description = metadata[:description]
65
+ example_group = if metadata.key?(:example_group)
66
+ metadata[:example_group]
67
+ else
68
+ metadata[:parent_example_group]
69
+ end
70
+
71
+ if example_group
72
+ [vcr_cassette_name_for(example_group), description].join('/')
73
+ else
74
+ description
75
+ end
76
+ end
77
+
78
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristopher Bredemeier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-05 00:00:00.000000000 Z
11
+ date: 2015-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.8.7.6
125
+ - !ruby/object:Gem::Dependency
126
+ name: codeclimate-test-reporter
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: Repository like access to elasticseach indices
126
140
  email:
127
141
  - k.bredemeier@gmail.com
@@ -130,13 +144,18 @@ extensions: []
130
144
  extra_rdoc_files: []
131
145
  files:
132
146
  - ".gitignore"
147
+ - ".hound.yml"
133
148
  - ".rspec"
149
+ - ".rubocop.yml"
150
+ - ".ruby.yml"
151
+ - ".travis.yml"
134
152
  - Gemfile
135
153
  - LICENSE.txt
136
154
  - README.md
137
155
  - Rakefile
138
156
  - elastic_adapter.gemspec
139
157
  - example.env
158
+ - examples/basic_usage.rb
140
159
  - lib/elastic_adapter.rb
141
160
  - lib/elastic_adapter/decoration/count_response.rb
142
161
  - lib/elastic_adapter/decoration/decorator.rb
@@ -149,29 +168,41 @@ files:
149
168
  - lib/elastic_adapter/index.rb
150
169
  - lib/elastic_adapter/response.rb
151
170
  - lib/elastic_adapter/version.rb
171
+ - spec/cassettes/ElasticAdapter_Index/_count/empty_index.yml
152
172
  - spec/cassettes/ElasticAdapter_Index/_count/empty_index/is_a_response.yml
153
- - spec/cassettes/ElasticAdapter_Index/_count/empty_index/returs_the_amount_of_all_documents.yml
173
+ - spec/cassettes/ElasticAdapter_Index/_count/empty_index/returns_the_amount_of_all_documents.yml
174
+ - spec/cassettes/ElasticAdapter_Index/_count/not_empty_index.yml
154
175
  - spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/is_a_response.yml
155
176
  - spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/returns_1.yml
177
+ - spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present.yml
156
178
  - spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present/response/has_an_exception.yml
157
179
  - spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present/response/is_a_Response.yml
180
+ - spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response.yml
158
181
  - spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response/has_no_exception.yml
159
182
  - spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response/is_a_Response.yml
160
183
  - spec/cassettes/ElasticAdapter_Index/_delete_index/index_not_present/repsonse/has_an_exception.yml
161
184
  - spec/cassettes/ElasticAdapter_Index/_delete_index/index_not_present/repsonse/is_a_Response.yml
162
185
  - spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/has_no_exception.yml
186
+ - spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/has_no_exceptionElasticAdapter_Index/_delete_index/index_present/repsonse.yml
163
187
  - spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/is_a_Response.yml
188
+ - spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/is_a_ResponseElasticAdapter_Index/_delete_index/index_present/repsonse.yml
189
+ - spec/cassettes/ElasticAdapter_Index/_get/document_exists.yml
164
190
  - spec/cassettes/ElasticAdapter_Index/_get/document_exists/response/contains_the_document.yml
191
+ - spec/cassettes/ElasticAdapter_Index/_index/existing_document.yml
165
192
  - spec/cassettes/ElasticAdapter_Index/_index/existing_document/doesn_t_change_the_document_count.yml
166
193
  - spec/cassettes/ElasticAdapter_Index/_index/existing_document/invokes_to_hash_on_the_document.yml
167
194
  - spec/cassettes/ElasticAdapter_Index/_index/existing_document/updates_the_document.yml
195
+ - spec/cassettes/ElasticAdapter_Index/_index/new_document.yml
168
196
  - spec/cassettes/ElasticAdapter_Index/_index/new_document/indexes_a_document.yml
169
197
  - spec/cassettes/ElasticAdapter_Index/_index/new_document/invokes_to_hash_on_the_document.yml
198
+ - spec/cassettes/ElasticAdapter_Index/_search.yml
170
199
  - spec/cassettes/ElasticAdapter_Index/_search/match_all/returns_all_documents.yml
171
200
  - spec/cassettes/ElasticAdapter_Index/_search/zoo/returns_one_document.yml
172
201
  - spec/cassettes/ElasticAdapter_Index/_search/zoo/returns_the_wanted_document.yml
202
+ - spec/cassettes/ElasticAdapter_Index/_suggest.yml
173
203
  - spec/cassettes/ElasticAdapter_Index/_suggest/query_ba_/returns_bar.yml
174
204
  - spec/cassettes/ElasticAdapter_Index/_suggest/query_ba_/returns_one_result.yml
205
+ - spec/cassettes/ElasticAdapter_Index/_validate.yml
175
206
  - spec/cassettes/ElasticAdapter_Index/_validate/invalid_query/is_a_response.yml
176
207
  - spec/cassettes/ElasticAdapter_Index/_validate/invalid_query/is_false.yml
177
208
  - spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_a_response.yml
@@ -179,9 +210,20 @@ files:
179
210
  - spec/decoration/response_decorator_factory_spec.rb
180
211
  - spec/document_type_spec.rb
181
212
  - spec/elastic_adapter_spec.rb
182
- - spec/index_spec.rb
213
+ - spec/index/count_spec.rb
214
+ - spec/index/create_index_spec.rb
215
+ - spec/index/delete_index_spec.rb
216
+ - spec/index/get_spec.rb
217
+ - spec/index/index_spec.rb
218
+ - spec/index/search_spec.rb
219
+ - spec/index/shared_context.rb
220
+ - spec/index/shared_examples.rb
221
+ - spec/index/suggest_spec.rb
222
+ - spec/index/unit_spec.rb
223
+ - spec/index/validate_spec.rb
183
224
  - spec/response_spec.rb
184
225
  - spec/spec_helper.rb
226
+ - spec/support/index_helper.rb
185
227
  homepage: https://github.com/kbredemeier/elastic_adatper
186
228
  licenses:
187
229
  - MIT
@@ -202,34 +244,46 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
244
  version: '0'
203
245
  requirements: []
204
246
  rubyforge_project:
205
- rubygems_version: 2.2.2
247
+ rubygems_version: 2.4.6
206
248
  signing_key:
207
249
  specification_version: 4
208
250
  summary: Repository like access to elasticseach indices
209
251
  test_files:
252
+ - spec/cassettes/ElasticAdapter_Index/_count/empty_index.yml
210
253
  - spec/cassettes/ElasticAdapter_Index/_count/empty_index/is_a_response.yml
211
- - spec/cassettes/ElasticAdapter_Index/_count/empty_index/returs_the_amount_of_all_documents.yml
254
+ - spec/cassettes/ElasticAdapter_Index/_count/empty_index/returns_the_amount_of_all_documents.yml
255
+ - spec/cassettes/ElasticAdapter_Index/_count/not_empty_index.yml
212
256
  - spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/is_a_response.yml
213
257
  - spec/cassettes/ElasticAdapter_Index/_count/not_empty_index/returns_1.yml
258
+ - spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present.yml
214
259
  - spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present/response/has_an_exception.yml
215
260
  - spec/cassettes/ElasticAdapter_Index/_create_index/index_is_present/response/is_a_Response.yml
261
+ - spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response.yml
216
262
  - spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response/has_no_exception.yml
217
263
  - spec/cassettes/ElasticAdapter_Index/_create_index/index_not_present/response/is_a_Response.yml
218
264
  - spec/cassettes/ElasticAdapter_Index/_delete_index/index_not_present/repsonse/has_an_exception.yml
219
265
  - spec/cassettes/ElasticAdapter_Index/_delete_index/index_not_present/repsonse/is_a_Response.yml
220
266
  - spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/has_no_exception.yml
267
+ - spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/has_no_exceptionElasticAdapter_Index/_delete_index/index_present/repsonse.yml
221
268
  - spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/is_a_Response.yml
269
+ - spec/cassettes/ElasticAdapter_Index/_delete_index/index_present/repsonse/is_a_ResponseElasticAdapter_Index/_delete_index/index_present/repsonse.yml
270
+ - spec/cassettes/ElasticAdapter_Index/_get/document_exists.yml
222
271
  - spec/cassettes/ElasticAdapter_Index/_get/document_exists/response/contains_the_document.yml
272
+ - spec/cassettes/ElasticAdapter_Index/_index/existing_document.yml
223
273
  - spec/cassettes/ElasticAdapter_Index/_index/existing_document/doesn_t_change_the_document_count.yml
224
274
  - spec/cassettes/ElasticAdapter_Index/_index/existing_document/invokes_to_hash_on_the_document.yml
225
275
  - spec/cassettes/ElasticAdapter_Index/_index/existing_document/updates_the_document.yml
276
+ - spec/cassettes/ElasticAdapter_Index/_index/new_document.yml
226
277
  - spec/cassettes/ElasticAdapter_Index/_index/new_document/indexes_a_document.yml
227
278
  - spec/cassettes/ElasticAdapter_Index/_index/new_document/invokes_to_hash_on_the_document.yml
279
+ - spec/cassettes/ElasticAdapter_Index/_search.yml
228
280
  - spec/cassettes/ElasticAdapter_Index/_search/match_all/returns_all_documents.yml
229
281
  - spec/cassettes/ElasticAdapter_Index/_search/zoo/returns_one_document.yml
230
282
  - spec/cassettes/ElasticAdapter_Index/_search/zoo/returns_the_wanted_document.yml
283
+ - spec/cassettes/ElasticAdapter_Index/_suggest.yml
231
284
  - spec/cassettes/ElasticAdapter_Index/_suggest/query_ba_/returns_bar.yml
232
285
  - spec/cassettes/ElasticAdapter_Index/_suggest/query_ba_/returns_one_result.yml
286
+ - spec/cassettes/ElasticAdapter_Index/_validate.yml
233
287
  - spec/cassettes/ElasticAdapter_Index/_validate/invalid_query/is_a_response.yml
234
288
  - spec/cassettes/ElasticAdapter_Index/_validate/invalid_query/is_false.yml
235
289
  - spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_a_response.yml
@@ -237,7 +291,18 @@ test_files:
237
291
  - spec/decoration/response_decorator_factory_spec.rb
238
292
  - spec/document_type_spec.rb
239
293
  - spec/elastic_adapter_spec.rb
240
- - spec/index_spec.rb
294
+ - spec/index/count_spec.rb
295
+ - spec/index/create_index_spec.rb
296
+ - spec/index/delete_index_spec.rb
297
+ - spec/index/get_spec.rb
298
+ - spec/index/index_spec.rb
299
+ - spec/index/search_spec.rb
300
+ - spec/index/shared_context.rb
301
+ - spec/index/shared_examples.rb
302
+ - spec/index/suggest_spec.rb
303
+ - spec/index/unit_spec.rb
304
+ - spec/index/validate_spec.rb
241
305
  - spec/response_spec.rb
242
306
  - spec/spec_helper.rb
307
+ - spec/support/index_helper.rb
243
308
  has_rdoc: