flex 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +20 -0
  3. data/VERSION +1 -0
  4. data/flex.gemspec +43 -0
  5. data/lib/flex.rb +418 -0
  6. data/lib/flex/api_methods.yml +108 -0
  7. data/lib/flex/class_proxy.rb +12 -0
  8. data/lib/flex/configuration.rb +57 -0
  9. data/lib/flex/errors.rb +42 -0
  10. data/lib/flex/http_clients/patron.rb +27 -0
  11. data/lib/flex/http_clients/rest_client.rb +38 -0
  12. data/lib/flex/loader.rb +116 -0
  13. data/lib/flex/logger.rb +16 -0
  14. data/lib/flex/model.rb +24 -0
  15. data/lib/flex/model/class_proxy.rb +45 -0
  16. data/lib/flex/model/instance_proxy.rb +101 -0
  17. data/lib/flex/model/manager.rb +67 -0
  18. data/lib/flex/rails.rb +12 -0
  19. data/lib/flex/rails/engine.rb +23 -0
  20. data/lib/flex/rails/helper.rb +16 -0
  21. data/lib/flex/related_model.rb +16 -0
  22. data/lib/flex/related_model/class_proxy.rb +23 -0
  23. data/lib/flex/related_model/class_sync.rb +23 -0
  24. data/lib/flex/related_model/instance_proxy.rb +28 -0
  25. data/lib/flex/result.rb +18 -0
  26. data/lib/flex/result/bulk.rb +20 -0
  27. data/lib/flex/result/collection.rb +51 -0
  28. data/lib/flex/result/document.rb +38 -0
  29. data/lib/flex/result/indifferent_access.rb +11 -0
  30. data/lib/flex/result/search.rb +51 -0
  31. data/lib/flex/result/source_document.rb +63 -0
  32. data/lib/flex/result/source_search.rb +32 -0
  33. data/lib/flex/structure/indifferent_access.rb +44 -0
  34. data/lib/flex/structure/mergeable.rb +21 -0
  35. data/lib/flex/tasks.rb +141 -0
  36. data/lib/flex/template.rb +187 -0
  37. data/lib/flex/template/base.rb +29 -0
  38. data/lib/flex/template/info.rb +50 -0
  39. data/lib/flex/template/partial.rb +31 -0
  40. data/lib/flex/template/search.rb +30 -0
  41. data/lib/flex/template/slim_search.rb +13 -0
  42. data/lib/flex/template/tags.rb +46 -0
  43. data/lib/flex/utility_methods.rb +140 -0
  44. data/lib/flex/utils.rb +59 -0
  45. data/lib/flex/variables.rb +11 -0
  46. data/lib/generators/flex/setup/setup_generator.rb +51 -0
  47. data/lib/generators/flex/setup/templates/flex_config.yml +16 -0
  48. data/lib/generators/flex/setup/templates/flex_dir/es.rb.erb +18 -0
  49. data/lib/generators/flex/setup/templates/flex_dir/es.yml.erb +19 -0
  50. data/lib/generators/flex/setup/templates/flex_dir/es_extender.rb.erb +17 -0
  51. data/lib/generators/flex/setup/templates/flex_initializer.rb.erb +44 -0
  52. data/lib/tasks/index.rake +23 -0
  53. data/test/flex.irt +143 -0
  54. data/test/flex/configuration.irt +53 -0
  55. data/test/irt_helper.rb +12 -0
  56. metadata +211 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 by Domizio Demichelis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # Flex
2
+
3
+ Flex is a complete ruby client for [ElasticSearch](http://www.elasticsearch.org). It introduces a new way to send any kind of request (not just search queries) to the ES server, and to manage any kind of response. You can transparently integrate it with **ActiveRecord** and **Mongoid** models with or without automatic synchronization, with or without **Rails**. It is fast and efficient, easy to use and customize.
4
+
5
+ Flex is currently a very new project, however it is already used in production in 5 sites, and it will be deployed to a few others soon.
6
+
7
+ ## Useful Links
8
+
9
+ * [Documentation](./flex/wiki)
10
+ * [Issues](./flex/issues)
11
+ * [Pull Requests](./flex/pulls)
12
+
13
+ ## Credits
14
+
15
+ Special thanks for their sponsorship to [Escalate Media](http://www.escalatemedia.com) and [Barquin International](http://www.barquin.com).
16
+
17
+ ## Copyright
18
+
19
+ Copyright (c) 2012 by [Domizio Demichelis](mailto://dd.nexus@gmail.com)<br>
20
+ See [LICENSE](./flex/blob/master/LICENSE) for details.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/flex.gemspec ADDED
@@ -0,0 +1,43 @@
1
+ require 'date'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'flex'
5
+ s.summary = 'Ruby Client for ElasticSearch'
6
+ s.description = <<-desc
7
+ Flex is a complete ruby client for ElasticSearch. It introduces a new way to send any kind of request (not just search queries) to the ES server, and to manage any kind of response. You can transparently integrate it with ActiveRecord and MongoId models with or without automatic synchronization, with or without Rails. It is fast and efficient, easy to use and customize.
8
+ desc
9
+ s.homepage = 'http://github.com/ddnexus/flex'
10
+ s.authors = ["Domizio Demichelis"]
11
+ s.email = 'dd.nexus@gmail.com'
12
+ s.extra_rdoc_files = %w[README.md]
13
+ s.require_paths = %w[lib]
14
+ s.files = `git ls-files -z`.split("\0")
15
+ s.version = File.read(File.expand_path('../VERSION', __FILE__)).strip
16
+ s.date = Date.today.to_s
17
+ s.required_rubygems_version = ">= 1.3.6"
18
+ s.rdoc_options = %w[--charset=UTF-8]
19
+ s.post_install_message = <<EOM
20
+ ________________________________________________________________________________
21
+
22
+ INSTALLATION NOTES
23
+ ________________________________________________________________________________
24
+
25
+ In order to use Flex, a supported http-client must be installed on this system.
26
+
27
+ The suported http-client gems are "patron" and "rest-client".
28
+
29
+ You should install "patron" (a libcurl based gem developed in C) for best
30
+ performances, or install "rest-client" if you cannot use libcurl on your system.
31
+
32
+ As an alternative you could eventually develop your own http-client interface
33
+ and set the Flex::Configuration.http_client option.
34
+
35
+ ________________________________________________________________________________
36
+ EOM
37
+ s.add_runtime_dependency 'multi_json', '~> 1.3.4'
38
+ s.add_runtime_dependency 'progressbar', '~> 0.11.0'
39
+ s.add_runtime_dependency 'prompter', '~> 0.1.5'
40
+ s.add_development_dependency 'irt', '~> 1.2.10'
41
+ s.add_development_dependency 'patron', '~> 0.4.18'
42
+ s.add_development_dependency 'rest-client', '~> 1.6.7'
43
+ end
data/lib/flex.rb ADDED
@@ -0,0 +1,418 @@
1
+ require 'yaml'
2
+ require 'ostruct'
3
+ require 'erb'
4
+ require 'multi_json'
5
+ require 'flex/logger'
6
+ require 'flex/errors'
7
+ require 'flex/utils'
8
+ require 'flex/structure/indifferent_access'
9
+ require 'flex/structure/mergeable'
10
+ require 'flex/result'
11
+ require 'flex/result/collection'
12
+ require 'flex/result/document'
13
+ require 'flex/result/source_document'
14
+ require 'flex/result/search'
15
+ require 'flex/result/source_search'
16
+ require 'flex/result/bulk'
17
+ require 'flex/variables'
18
+ require 'flex/template/base'
19
+ require 'flex/template/partial'
20
+ require 'flex/template'
21
+ require 'flex/template/search'
22
+ require 'flex/template/slim_search'
23
+ require 'flex/template/tags'
24
+ require 'flex/template/info'
25
+ require 'flex/class_proxy'
26
+ require 'flex/loader'
27
+ require 'flex/model/manager'
28
+ require 'flex/related_model'
29
+ require 'flex/related_model/class_sync'
30
+ require 'flex/related_model/class_proxy'
31
+ require 'flex/related_model/instance_proxy'
32
+ require 'flex/model'
33
+ require 'flex/model/class_proxy'
34
+ require 'flex/model/instance_proxy'
35
+ require 'flex/http_clients/patron'
36
+ require 'flex/http_clients/rest_client'
37
+ require 'flex/configuration'
38
+ require 'flex/utility_methods'
39
+
40
+ module Flex
41
+
42
+ VERSION = File.read(File.expand_path('../../VERSION', __FILE__)).strip
43
+
44
+ # The following lines are autogenerated by Flex.info
45
+
46
+ # ########## Flex.indices_exists ##########
47
+ #
48
+ # Flex::Template:
49
+ # ---
50
+ # indices_exists:
51
+ # - HEAD
52
+ # - /<<index>>
53
+ #
54
+ # Usage:
55
+ # Flex.indices_exists :index => "flex_test_index"
56
+ #
57
+ def Flex.indices_exists(vars={})
58
+ # this is a stub, used for reference
59
+ end
60
+
61
+
62
+ # ########## Flex.exist? ##########
63
+ #
64
+ # Flex::Template:
65
+ # ---
66
+ # exist?:
67
+ # - HEAD
68
+ # - /<<index>>
69
+ #
70
+ # Usage:
71
+ # Flex.exist? :index => "flex_test_index"
72
+ #
73
+ def Flex.exist?(vars={})
74
+ # this is a stub, used for reference
75
+ end
76
+
77
+
78
+ # ########## Flex.create_index ##########
79
+ #
80
+ # Flex::Template:
81
+ # ---
82
+ # create_index:
83
+ # - PUT
84
+ # - /<<index>>
85
+ # - settings:
86
+ # number_of_shards: <<number_of_shards= 5 >>
87
+ # number_of_replicas: <<number_of_replicas= 1 >>
88
+ #
89
+ # Usage:
90
+ # Flex.create_index :index => "flex_test_index",
91
+ # :number_of_shards => 5,
92
+ # :number_of_replicas => 1
93
+ #
94
+ def Flex.create_index(vars={})
95
+ # this is a stub, used for reference
96
+ end
97
+
98
+
99
+ # ########## Flex.put_index ##########
100
+ #
101
+ # Flex::Template:
102
+ # ---
103
+ # put_index:
104
+ # - PUT
105
+ # - /<<index>>
106
+ # - settings:
107
+ # number_of_shards: <<number_of_shards= 5 >>
108
+ # number_of_replicas: <<number_of_replicas= 1 >>
109
+ #
110
+ # Usage:
111
+ # Flex.put_index :index => "flex_test_index",
112
+ # :number_of_shards => 5,
113
+ # :number_of_replicas => 1
114
+ #
115
+ def Flex.put_index(vars={})
116
+ # this is a stub, used for reference
117
+ end
118
+
119
+
120
+ # ########## Flex.post_index ##########
121
+ #
122
+ # Flex::Template:
123
+ # ---
124
+ # post_index:
125
+ # - POST
126
+ # - /<<index>>
127
+ # - settings:
128
+ # number_of_shards: <<number_of_shards= 5 >>
129
+ # number_of_replicas: <<number_of_replicas= 1 >>
130
+ #
131
+ # Usage:
132
+ # Flex.post_index :index => "flex_test_index",
133
+ # :number_of_shards => 5,
134
+ # :number_of_replicas => 1
135
+ #
136
+ def Flex.post_index(vars={})
137
+ # this is a stub, used for reference
138
+ end
139
+
140
+
141
+ # ########## Flex.get_settings ##########
142
+ #
143
+ # Flex::Template:
144
+ # ---
145
+ # get_settings:
146
+ # - GET
147
+ # - /<<index>>/_settings
148
+ #
149
+ # Usage:
150
+ # Flex.get_settings :index => "flex_test_index"
151
+ #
152
+ def Flex.get_settings(vars={})
153
+ # this is a stub, used for reference
154
+ end
155
+
156
+
157
+ # ########## Flex.put_mapping ##########
158
+ #
159
+ # Flex::Template:
160
+ # ---
161
+ # put_mapping:
162
+ # - PUT
163
+ # - /<<index>>/<<type>>/_mapping
164
+ # - <<type>>:
165
+ # properties: <<properties>>
166
+ #
167
+ # Usage:
168
+ # Flex.put_mapping :properties => properties, # required
169
+ # :type => nil,
170
+ # :index => "flex_test_index"
171
+ #
172
+ def Flex.put_mapping(vars={})
173
+ # this is a stub, used for reference
174
+ end
175
+
176
+
177
+ # ########## Flex.get_mapping ##########
178
+ #
179
+ # Flex::Template:
180
+ # ---
181
+ # get_mapping:
182
+ # - GET
183
+ # - /<<index>>/<<type>>/_mapping
184
+ #
185
+ # Usage:
186
+ # Flex.get_mapping :index => "flex_test_index",
187
+ # :type => nil
188
+ #
189
+ def Flex.get_mapping(vars={})
190
+ # this is a stub, used for reference
191
+ end
192
+
193
+
194
+ # ########## Flex.delete_mapping ##########
195
+ #
196
+ # Flex::Template:
197
+ # ---
198
+ # delete_mapping:
199
+ # - DELETE
200
+ # - /<<index>>/<<type>>
201
+ #
202
+ # Usage:
203
+ # Flex.delete_mapping :index => "flex_test_index",
204
+ # :type => nil
205
+ #
206
+ def Flex.delete_mapping(vars={})
207
+ # this is a stub, used for reference
208
+ end
209
+
210
+
211
+ # ########## Flex.delete_index ##########
212
+ #
213
+ # Flex::Template:
214
+ # ---
215
+ # delete_index:
216
+ # - DELETE
217
+ # - /<<index>>
218
+ #
219
+ # Usage:
220
+ # Flex.delete_index :index => "flex_test_index"
221
+ #
222
+ def Flex.delete_index(vars={})
223
+ # this is a stub, used for reference
224
+ end
225
+
226
+
227
+ # ########## Flex.delete_by_query ##########
228
+ #
229
+ # Flex::Template:
230
+ # ---
231
+ # delete_by_query:
232
+ # - DELETE
233
+ # - /<<index>>/<<type>>/_query
234
+ #
235
+ # Usage:
236
+ # Flex.delete_by_query :index => "flex_test_index",
237
+ # :type => nil
238
+ #
239
+ def Flex.delete_by_query(vars={})
240
+ # this is a stub, used for reference
241
+ end
242
+
243
+
244
+ # ########## Flex.bulk ##########
245
+ #
246
+ # Flex::Template:
247
+ # ---
248
+ # bulk:
249
+ # - POST
250
+ # - /_bulk
251
+ # - << lines >>
252
+ #
253
+ # Usage:
254
+ # Flex.bulk :lines => lines # required
255
+ #
256
+ def Flex.bulk(vars={})
257
+ # this is a stub, used for reference
258
+ end
259
+
260
+
261
+ # ########## Flex.count ##########
262
+ #
263
+ # Flex::Template:
264
+ # ---
265
+ # count:
266
+ # - GET
267
+ # - /<<index>>/<<type>>/_count
268
+ #
269
+ # Usage:
270
+ # Flex.count :index => "flex_test_index",
271
+ # :type => nil
272
+ #
273
+ def Flex.count(vars={})
274
+ # this is a stub, used for reference
275
+ end
276
+
277
+
278
+ # ########## Flex.stats ##########
279
+ #
280
+ # Flex::Template:
281
+ # ---
282
+ # stats:
283
+ # - GET
284
+ # - /<<index>>/_stats/<<end_point= ~ >>
285
+ #
286
+ # Usage:
287
+ # Flex.stats :index => "flex_test_index",
288
+ # :end_point => nil
289
+ #
290
+ def Flex.stats(vars={})
291
+ # this is a stub, used for reference
292
+ end
293
+
294
+
295
+ # ########## Flex.store ##########
296
+ #
297
+ # Flex::Template:
298
+ # ---
299
+ # store:
300
+ # - PUT
301
+ # - /<<index>>/<<type>>/<<id>>
302
+ #
303
+ # Usage:
304
+ # Flex.store :id => id, # required
305
+ # :type => nil,
306
+ # :index => "flex_test_index"
307
+ #
308
+ def Flex.store(vars={})
309
+ # this is a stub, used for reference
310
+ end
311
+
312
+
313
+ # ########## Flex.put_store ##########
314
+ #
315
+ # Flex::Template:
316
+ # ---
317
+ # put_store:
318
+ # - PUT
319
+ # - /<<index>>/<<type>>/<<id>>
320
+ #
321
+ # Usage:
322
+ # Flex.put_store :id => id, # required
323
+ # :type => nil,
324
+ # :index => "flex_test_index"
325
+ #
326
+ def Flex.put_store(vars={})
327
+ # this is a stub, used for reference
328
+ end
329
+
330
+
331
+ # ########## Flex.post_store ##########
332
+ #
333
+ # Flex::Template:
334
+ # ---
335
+ # post_store:
336
+ # - POST
337
+ # - /<<index>>/<<type>>
338
+ #
339
+ # Usage:
340
+ # Flex.post_store :index => "flex_test_index",
341
+ # :type => nil
342
+ #
343
+ def Flex.post_store(vars={})
344
+ # this is a stub, used for reference
345
+ end
346
+
347
+
348
+ # ########## Flex.remove ##########
349
+ #
350
+ # Flex::Template:
351
+ # ---
352
+ # remove:
353
+ # - DELETE
354
+ # - /<<index>>/<<type>>/<<id>>
355
+ #
356
+ # Usage:
357
+ # Flex.remove :id => id, # required
358
+ # :type => nil,
359
+ # :index => "flex_test_index"
360
+ #
361
+ def Flex.remove(vars={})
362
+ # this is a stub, used for reference
363
+ end
364
+
365
+
366
+ # ########## Flex.get ##########
367
+ #
368
+ # Flex::Template:
369
+ # ---
370
+ # get:
371
+ # - GET
372
+ # - /<<index>>/<<type>>/<<id>>
373
+ #
374
+ # Usage:
375
+ # Flex.get :id => id, # required
376
+ # :type => nil,
377
+ # :index => "flex_test_index"
378
+ #
379
+ def Flex.get(vars={})
380
+ # this is a stub, used for reference
381
+ end
382
+
383
+
384
+ # ########## Flex.multi_get ##########
385
+ #
386
+ # Flex::Template:
387
+ # ---
388
+ # multi_get:
389
+ # - GET
390
+ # - /<<index>>/<<type>>/_mget
391
+ # - ids: << ids >>
392
+ #
393
+ # Usage:
394
+ # Flex.multi_get :ids => ids, # required
395
+ # :type => nil,
396
+ # :index => "flex_test_index"
397
+ #
398
+ def Flex.multi_get(vars={})
399
+ # this is a stub, used for reference
400
+ end
401
+
402
+ include Loader
403
+ flex.load_source File.expand_path('../flex/api_methods.yml', __FILE__)
404
+
405
+ extend self
406
+ extend UtilityMethods
407
+
408
+ def reload!
409
+ flex.variables = Configuration.variables.deep_dup
410
+ Loader.host_classes.each {|c| c.flex.reload!}
411
+ true
412
+ end
413
+
414
+ def info(*args)
415
+ flex.info *args
416
+ end
417
+
418
+ end