sequel-elasticsearch 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a1b9f57743a4f411f924497691250d65ef79dcec
4
+ data.tar.gz: cca07116bde1f723925469d8587a2cf8e303cb36
5
+ SHA512:
6
+ metadata.gz: c099502b9b552e0399d9861ac24db496af9436a550a94d36561df4406af49b7567cad8c8e9b242e4240b075de1fb74255d33a1957deaa09e3d8839befee7a89b
7
+ data.tar.gz: 2bdc291308bda70e04a01ee04fc138417b73a37c4430f78495a194d3906f803ae7760813c46dadfa174dc18edf1a0dddf619d6ef84bef0f7969a26af1f3721da
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.*.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+ Style/Documentation:
4
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,29 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.6
5
+ - 2.4.3
6
+ - 2.5.0
7
+ gemfile: Gemfile.ci
8
+ env:
9
+ global:
10
+ - CC_TEST_REPORTER_ID=f35fd15664b071c621a239733eb3b063caf333ac7e795d3a20690942f64caf62
11
+ before_install:
12
+ - gem install bundler -v 1.13.6
13
+ before_script:
14
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
15
+ > ./cc-test-reporter
16
+ - chmod +x ./cc-test-reporter
17
+ - "./cc-test-reporter before-build"
18
+ after_script:
19
+ - "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
20
+ deploy:
21
+ provider: rubygems
22
+ gem: sequel-elasticsearch
23
+ on:
24
+ tags: true
25
+ repo: jrgns/sequel-elasticsearch
26
+ api_key:
27
+ secure: xP8zLfBbDTTUpJP8DUL9llfGIGwuTkifmySfoTo7YHOoEC9hFhviT2+PdeoTLywjAIsIwjvghzB2rBERcAPkbu1ahVow9+/0n3jV4UmgRNm2bFcAlIEb8j2gSUlK/ETrIXRBUTUnMg60qhaxIIPd5VQY4eOv2EbmujUqfJgN6xJTTQkiuN4G/UK6Cbhi9d1YDcviY/un9XKIRZQuUvkHQ9vBpK2xJEmisymg0ljK/uj9/dAjKUtyZ7c3QKjcTcQeZ/YKxkKuwaTO5TyHTfKkzUS6M9wS280zbHj3KS98xYX1NTGqDTlq1YPPKAtedhh1+xiCoT50BcIFHmOAymTfvMeGrRQp4fxGOaLMV3q9hP91PAY/Eul3B4gJrAulDahc5xy4TECvM+GdIitNHWpXchH3iE70vWybjFFOTRrf4ftjh20BbeaGJG2FVLD4haC8Y73B6Q8Yf2/qu9Wc+vyXkCXRwiGBl+x1N1gmRoF2w5jyMfEnAJ/7wN4sTcLRvN8PViOKbZ9cNyjgsdwoJoqcH045HJhyRALl5pXeoTANzyPw7Dm2yGyzw2Rnv3TqJD4eeJr8dQyQgR83P7yl/GDrG493QY0Mkl8iMEmS/GFTX6L4p7qqiJqDYBtIuW4/XET2Ui7HrV/5midzTiC5nGNZdHkQkLNMlkIvaSpROXV058I=
28
+ after_success:
29
+ - bundle exec codeclimate-test-reporter
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sequel-elasticsearch.gemspec
4
+ gemspec
data/Gemfile.ci ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in proxes.gemspec
4
+ gemspec
5
+
6
+ gem 'sqlite3'
data/Gemfile.dev ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'elasticsearch'
4
+ gem 'rake'
5
+ gem 'rspec'
6
+ gem 'rubocop'
7
+ gem 'sequel'
8
+ gem 'simplecov'
9
+ gem 'webmock'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Jurgens du Toit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # Sequel::Elasticsearch
2
+
3
+ Sequel::Elasticsearch allows you to transparently mirror your database, or specific tables, to Elasticsearch. It's especially useful if you want the power of search through Elasticsearch, but keep the sanity and structure of a relational database.
4
+
5
+ [![Build Status](https://travis-ci.org/jrgns/sequel-elasticsearch.svg?branch=master)](https://travis-ci.org/jrgns/sequel-elasticsearch)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/ff453fe81303a2fa7c02/maintainability)](https://codeclimate.com/github/jrgns/sequel-elasticsearch/maintainability)
7
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/ff453fe81303a2fa7c02/test_coverage)](https://codeclimate.com/github/jrgns/sequel-elasticsearch/test_coverage)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'sequel-elasticsearch'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install sequel-elasticsearch
24
+
25
+ ## Usage
26
+
27
+ You firstly need an Elasticsearch cluster to sync your data to. By default the gem will try to connect to `http://localhost:9200`. Set the `ELASTICSEARCH_URL` ENV variable to the URL of your cluster.
28
+
29
+ This is a Sequel plugin, so you can enable it DB wide:
30
+
31
+ ```ruby
32
+ Sequel::Model.plugin :elasticsearch
33
+
34
+ ```
35
+
36
+ Or per model:
37
+
38
+ ```ruby
39
+ Sequel::Model.plugin Sequel::Elasticsearch
40
+
41
+ # or
42
+
43
+ class Node < Sequel::Model
44
+ plugin :elasticsearch
45
+ end
46
+ ```
47
+
48
+ There's a couple of options you can set:
49
+
50
+ ```ruby
51
+ Sequel::Model.plugin :elasticsearch,
52
+ elasticsearch: { log: true }, # Options to pass the the Elasticsearch ruby client
53
+ index: 'all-my-data', # The index in which the data should be stored. Defaults to the table name associated with the model
54
+ type: 'is-mine' # The type in which the data should be stored.
55
+ ```
56
+
57
+ And that's it! Just transact as you normally would, and your records will be created and updated in the Elasticsearch cluster.
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jrgns/sequel-elasticsearch.
68
+
69
+ Features that needs to be built:
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.
73
+ - [ ] A rake task to create or suggest mappings for a table.
74
+
75
+ ## License
76
+
77
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
78
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ libdir = File.expand_path(File.dirname(__FILE__) + '/lib')
2
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
3
+
4
+ require 'bundler/gem_tasks'
5
+ begin
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ rescue LoadError
9
+ puts 'Did not load RSpec'
10
+ end
11
+
12
+ task default: :spec
@@ -0,0 +1,72 @@
1
+ require 'elasticsearch'
2
+
3
+ module Sequel
4
+ module Plugins
5
+ module Elasticsearch
6
+ def self.apply(model, _opts = OPTS)
7
+ model.instance_variable_set(:@elasticsearch_opts, {})
8
+ model.instance_variable_set(:@elasticsearch_index, nil)
9
+ model.instance_variable_set(:@elasticsearch_type, 'sync')
10
+ model
11
+ end
12
+
13
+ def self.configure(model, opts = OPTS)
14
+ model.elasticsearch_opts = opts[:elasticsearch] || {}
15
+ model.elasticsearch_index = (opts[:index] || model.table_name).to_sym
16
+ model.elasticsearch_type = (opts[:type] || :sync).to_sym
17
+ model
18
+ end
19
+
20
+ module ClassMethods
21
+ attr_accessor :elasticsearch_opts, :elasticsearch_index, :elasticsearch_type
22
+ end
23
+
24
+ module InstanceMethods
25
+ def after_create
26
+ super
27
+ index_document
28
+ end
29
+
30
+ def after_destroy
31
+ super
32
+ destroy_document
33
+ end
34
+
35
+ def after_update
36
+ super
37
+ index_document
38
+ end
39
+
40
+ def es_client
41
+ @es_client = ::Elasticsearch::Client.new self.class.elasticsearch_opts
42
+ end
43
+
44
+ private
45
+
46
+ def document_id
47
+ doc_id = pk
48
+ doc_id = doc_id.join('_') if doc_id.is_a? Array
49
+ doc_id
50
+ end
51
+
52
+ def document_path
53
+ {
54
+ index: self.class.elasticsearch_index,
55
+ type: self.class.elasticsearch_type,
56
+ id: document_id
57
+ }
58
+ end
59
+
60
+ def index_document
61
+ params = document_path
62
+ params[:body] = values
63
+ es_client.index params
64
+ end
65
+
66
+ def destroy_document
67
+ es_client.delete document_path
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ module Sequel
2
+ module Elasticsearch
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sequel/plugins/elasticsearch/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'sequel-elasticsearch'
8
+ spec.version = Sequel::Elasticsearch::VERSION
9
+ spec.authors = ['Jurgens du Toit']
10
+ spec.email = ['jrgns@jadeit.co.za']
11
+
12
+ spec.summary = 'A plugin for the Sequel gem to sync data to Elasticsearch.'
13
+ spec.description = 'A plugin for the Sequel gem to sync data to Elasticsearch.'
14
+ spec.homepage = 'https://github.com/jrgns/sequel-elasticsearch'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'elasticsearch', '~> 6.0'
25
+ spec.add_dependency 'sequel', '~> 5.4'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.13'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'rubocop', '~> 0.52'
31
+ spec.add_development_dependency 'simplecov', '~> 0.15'
32
+ spec.add_development_dependency 'webmock', '~> 3.2'
33
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel-elasticsearch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jurgens du Toit
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: elasticsearch
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sequel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.52'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.52'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.15'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.15'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.2'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.2'
125
+ description: A plugin for the Sequel gem to sync data to Elasticsearch.
126
+ email:
127
+ - jrgns@jadeit.co.za
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".rubocop.yml"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - Gemfile.ci
138
+ - Gemfile.dev
139
+ - LICENSE.txt
140
+ - README.md
141
+ - Rakefile
142
+ - lib/sequel/plugins/elasticsearch.rb
143
+ - lib/sequel/plugins/elasticsearch/version.rb
144
+ - sequel-elasticsearch.gemspec
145
+ homepage: https://github.com/jrgns/sequel-elasticsearch
146
+ licenses:
147
+ - MIT
148
+ metadata: {}
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 2.6.13
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: A plugin for the Sequel gem to sync data to Elasticsearch.
169
+ test_files: []