sequel-elasticsearch 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a1b9f57743a4f411f924497691250d65ef79dcec
4
- data.tar.gz: cca07116bde1f723925469d8587a2cf8e303cb36
2
+ SHA256:
3
+ metadata.gz: 3ec57146972164d9b3940a06d43f971d27b578db9a851f8ca90b33f6239b4f72
4
+ data.tar.gz: 21cc2da346ba2f249956e4b945b8cd4331ef4420eb670efb32ebe387bd3b9676
5
5
  SHA512:
6
- metadata.gz: c099502b9b552e0399d9861ac24db496af9436a550a94d36561df4406af49b7567cad8c8e9b242e4240b075de1fb74255d33a1957deaa09e3d8839befee7a89b
7
- data.tar.gz: 2bdc291308bda70e04a01ee04fc138417b73a37c4430f78495a194d3906f803ae7760813c46dadfa174dc18edf1a0dddf619d6ef84bef0f7969a26af1f3721da
6
+ metadata.gz: d2d560ca5424d915563d586dfc605b6ace4e660283472209a4152464ec165612080afb87d85ece0a1f59ea6884ea4a52f981c961fbb69d574b5f2202930eb936
7
+ data.tar.gz: f21cd9634945eb35227d0f65a882486c40ccc4c4c368144cb2978baba18376d7902ab553cd49aeeb01cae2738f3df71546aad756e3ee002890764087f617ee2c
data/README.md CHANGED
@@ -68,8 +68,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/jrgns/
68
68
 
69
69
  Features that needs to be built:
70
70
 
71
- - [ ] Asynchronous workers so that the updates can be processed in the background.
72
- - [ ] An `es` method to search through the data on the cluster.
71
+ - [x] An `es` method to search through the data on the cluster.
72
+ - [ ] Let `es` return an enumerator of `Sequel::Model` instances.
73
73
  - [ ] A rake task to create or suggest mappings for a table.
74
74
 
75
75
  ## License
@@ -19,26 +19,53 @@ module Sequel
19
19
 
20
20
  module ClassMethods
21
21
  attr_accessor :elasticsearch_opts, :elasticsearch_index, :elasticsearch_type
22
+
23
+ def es_client
24
+ @es_client = ::Elasticsearch::Client.new elasticsearch_opts
25
+ end
26
+
27
+ def es!(query = '', opts = {})
28
+ opts = {
29
+ index: elasticsearch_index,
30
+ type: elasticsearch_type
31
+ }.merge(opts)
32
+ query.is_a?(String) ? opts[:q] = query : opts[:body] = query
33
+ es_client.search opts
34
+ end
35
+
36
+ def es(query = '', opts = {})
37
+ call_es { es! query, opts }
38
+ end
39
+
40
+ def call_es
41
+ yield
42
+ rescue ::Elasticsearch::Transport::Transport::Errors::NotFound, ::Elasticsearch::Transport::Transport::Error => e
43
+ db.loggers.first.warn e if db.loggers.count.positive?
44
+ nil
45
+ rescue Faraday::ConnectionFailed => e
46
+ db.loggers.first.warn e if db.loggers.count.positive?
47
+ nil
48
+ end
22
49
  end
23
50
 
24
51
  module InstanceMethods
25
52
  def after_create
26
53
  super
27
- index_document
54
+ self.class.call_es { index_document }
28
55
  end
29
56
 
30
57
  def after_destroy
31
58
  super
32
- destroy_document
59
+ self.class.call_es { destroy_document }
33
60
  end
34
61
 
35
62
  def after_update
36
63
  super
37
- index_document
64
+ self.class.call_es { index_document }
38
65
  end
39
66
 
40
67
  def es_client
41
- @es_client = ::Elasticsearch::Client.new self.class.elasticsearch_opts
68
+ self.class.es_client
42
69
  end
43
70
 
44
71
  private
@@ -1,5 +1,5 @@
1
1
  module Sequel
2
2
  module Elasticsearch
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurgens du Toit
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-03 00:00:00.000000000 Z
11
+ date: 2018-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  version: '0'
163
163
  requirements: []
164
164
  rubyforge_project:
165
- rubygems_version: 2.6.13
165
+ rubygems_version: 2.7.4
166
166
  signing_key:
167
167
  specification_version: 4
168
168
  summary: A plugin for the Sequel gem to sync data to Elasticsearch.