esse 0.0.3 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exec/esse +3 -1
- data/lib/esse/backend/index/aliases.rb +8 -4
- data/lib/esse/backend/index/close.rb +6 -5
- data/lib/esse/backend/index/create.rb +20 -9
- data/lib/esse/backend/index/delete.rb +15 -14
- data/lib/esse/backend/index/documents.rb +2 -2
- data/lib/esse/backend/index/existance.rb +2 -3
- data/lib/esse/backend/index/open.rb +6 -5
- data/lib/esse/backend/index/refresh.rb +43 -0
- data/lib/esse/backend/index/reset.rb +33 -0
- data/lib/esse/backend/index/update.rb +37 -15
- data/lib/esse/backend/index.rb +18 -4
- data/lib/esse/backend/index_type/documents.rb +53 -42
- data/lib/esse/backend/index_type.rb +7 -2
- data/lib/esse/cli/event_listener.rb +87 -0
- data/lib/esse/cli/generate.rb +9 -4
- data/lib/esse/cli/index/base_operation.rb +76 -0
- data/lib/esse/cli/index/close.rb +26 -0
- data/lib/esse/cli/index/create.rb +26 -0
- data/lib/esse/cli/index/delete.rb +26 -0
- data/lib/esse/cli/index/import.rb +26 -0
- data/lib/esse/cli/index/open.rb +26 -0
- data/lib/esse/cli/index/reset.rb +26 -0
- data/lib/esse/cli/index/update_aliases.rb +32 -0
- data/lib/esse/cli/index/update_mapping.rb +33 -0
- data/lib/esse/cli/index/update_settings.rb +26 -0
- data/lib/esse/cli/index.rb +78 -2
- data/lib/esse/cli/templates/config.rb.erb +20 -0
- data/lib/esse/cli/templates/index.rb.erb +76 -11
- data/lib/esse/cli/templates/type_collection.rb.erb +41 -0
- data/lib/esse/cli/templates/{mappings.json → type_mappings.json} +0 -0
- data/lib/esse/cli/templates/type_serializer.rb.erb +23 -0
- data/lib/esse/cli.rb +75 -3
- data/lib/esse/cluster.rb +22 -6
- data/lib/esse/config.rb +39 -5
- data/lib/esse/core.rb +18 -36
- data/lib/esse/errors.rb +47 -0
- data/lib/esse/events/bus.rb +103 -0
- data/lib/esse/events/event.rb +64 -0
- data/lib/esse/events/publisher.rb +119 -0
- data/lib/esse/events.rb +49 -0
- data/lib/esse/index/backend.rb +2 -1
- data/lib/esse/index/base.rb +4 -6
- data/lib/esse/index/mappings.rb +2 -3
- data/lib/esse/index/settings.rb +7 -8
- data/lib/esse/index.rb +2 -1
- data/lib/esse/index_mapping.rb +2 -2
- data/lib/esse/index_setting.rb +8 -4
- data/lib/esse/index_type/actions.rb +2 -1
- data/lib/esse/index_type/backend.rb +2 -1
- data/lib/esse/index_type/mappings.rb +2 -2
- data/lib/esse/index_type.rb +6 -1
- data/lib/esse/logging.rb +19 -0
- data/lib/esse/object_document_mapper.rb +96 -0
- data/lib/esse/primitives/hash_utils.rb +40 -0
- data/lib/esse/primitives/hstring.rb +4 -3
- data/lib/esse/primitives/output.rb +64 -0
- data/lib/esse/primitives.rb +1 -0
- data/lib/esse/template_loader.rb +1 -1
- data/lib/esse/version.rb +1 -1
- data/lib/esse.rb +12 -3
- metadata +124 -21
- data/.gitignore +0 -12
- data/.rubocop.yml +0 -128
- data/CHANGELOG.md +0 -0
- data/Gemfile +0 -7
- data/Gemfile.lock +0 -60
- data/LICENSE.txt +0 -21
- data/README.md +0 -52
- data/Rakefile +0 -4
- data/bin/console +0 -22
- data/bin/setup +0 -8
- data/esse.gemspec +0 -39
- data/lib/esse/cli/templates/serializer.rb.erb +0 -14
- data/lib/esse/index_type/serializer.rb +0 -87
data/Gemfile.lock
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
esse (0.0.2)
|
5
|
-
elasticsearch
|
6
|
-
multi_json
|
7
|
-
thor (>= 0.19)
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
12
|
-
awesome_print (1.8.0)
|
13
|
-
coderay (1.1.2)
|
14
|
-
diff-lcs (1.3)
|
15
|
-
dotenv (2.7.5)
|
16
|
-
elasticsearch (7.6.0)
|
17
|
-
elasticsearch-api (= 7.6.0)
|
18
|
-
elasticsearch-transport (= 7.6.0)
|
19
|
-
elasticsearch-api (7.6.0)
|
20
|
-
multi_json
|
21
|
-
elasticsearch-transport (7.6.0)
|
22
|
-
faraday (~> 1)
|
23
|
-
multi_json
|
24
|
-
faraday (1.0.1)
|
25
|
-
multipart-post (>= 1.2, < 3)
|
26
|
-
method_source (0.9.1)
|
27
|
-
multi_json (1.14.1)
|
28
|
-
multipart-post (2.1.1)
|
29
|
-
pry (0.12.0)
|
30
|
-
coderay (~> 1.1.0)
|
31
|
-
method_source (~> 0.9.0)
|
32
|
-
rake (12.3.3)
|
33
|
-
rspec (3.9.0)
|
34
|
-
rspec-core (~> 3.9.0)
|
35
|
-
rspec-expectations (~> 3.9.0)
|
36
|
-
rspec-mocks (~> 3.9.0)
|
37
|
-
rspec-core (3.9.1)
|
38
|
-
rspec-support (~> 3.9.1)
|
39
|
-
rspec-expectations (3.9.1)
|
40
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
-
rspec-support (~> 3.9.0)
|
42
|
-
rspec-mocks (3.9.1)
|
43
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
-
rspec-support (~> 3.9.0)
|
45
|
-
rspec-support (3.9.2)
|
46
|
-
thor (1.0.1)
|
47
|
-
|
48
|
-
PLATFORMS
|
49
|
-
ruby
|
50
|
-
|
51
|
-
DEPENDENCIES
|
52
|
-
awesome_print
|
53
|
-
dotenv
|
54
|
-
esse!
|
55
|
-
pry
|
56
|
-
rake (~> 12.3)
|
57
|
-
rspec (~> 3.0)
|
58
|
-
|
59
|
-
BUNDLED WITH
|
60
|
-
2.1.4
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2020 Marcos G. Zimmermann
|
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
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# esse
|
2
|
-
|
3
|
-
**This project is under development and may suffer constant structural changes. I don't recommend using it right now**
|
4
|
-
|
5
|
-
Simple and efficient way to organize queries/mapping/indices/tasks based on the official elasticsearch-ruby.
|
6
|
-
|
7
|
-
## Why to use it?
|
8
|
-
Some facts to use this library:
|
9
|
-
|
10
|
-
### Don't spend time learning our DLS
|
11
|
-
You don't need to spend time learning our DSL or gem usage to start using it. All you need know is the elasticsearch syntax. You are free to build your queries/mappings/settings using JSON/RubyHash flexibility. And keeping simple any elasticsearch upgrade and its syntax changes.
|
12
|
-
|
13
|
-
### Multiple ElasticSearch Versions
|
14
|
-
You can use multiple elasticsearch servers with different versions in an elegant way. Take a look at [LINK TO TOPIC](#anchors-id-here) for more details.
|
15
|
-
|
16
|
-
### It's pure Ruby
|
17
|
-
Yeah!! Nor [activesupport](http://github.com/rails/rails/tree/master/activesupport) dependency and all its monkey patchings. But if you are using rails, suggest install `esse-rails` extension that makes things even easier. Use the [Get started with esse-rails](#anchors-id-here) for more details.
|
18
|
-
|
19
|
-
## Installation
|
20
|
-
|
21
|
-
Add this line to your application's Gemfile:
|
22
|
-
|
23
|
-
```ruby
|
24
|
-
gem 'esse'
|
25
|
-
```
|
26
|
-
|
27
|
-
And then execute:
|
28
|
-
|
29
|
-
$ bundle install
|
30
|
-
|
31
|
-
Or install it yourself as:
|
32
|
-
|
33
|
-
$ gem install esse
|
34
|
-
|
35
|
-
## Usage
|
36
|
-
|
37
|
-
TODO: Write usage instructions here
|
38
|
-
|
39
|
-
## Development
|
40
|
-
|
41
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
-
|
43
|
-
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).
|
44
|
-
|
45
|
-
## Contributing
|
46
|
-
|
47
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/marcosgz/esse.
|
48
|
-
|
49
|
-
|
50
|
-
## License
|
51
|
-
|
52
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'dotenv/load'
|
5
|
-
require 'esse'
|
6
|
-
require 'pry'
|
7
|
-
require 'awesome_print'
|
8
|
-
|
9
|
-
Esse.config.clusters.client = { url: ENV.fetch('ELASTICSEARCH_URL', 'http://localhost:9200') }
|
10
|
-
Esse.config.clusters.index_prefix = 'esse_console'
|
11
|
-
|
12
|
-
class ApplicationIndex < Esse::Index
|
13
|
-
self.abstract_class = true
|
14
|
-
end
|
15
|
-
class GeosIndex < ApplicationIndex
|
16
|
-
self.index_version = 'v1'
|
17
|
-
|
18
|
-
define_type :county
|
19
|
-
define_type :city
|
20
|
-
end
|
21
|
-
|
22
|
-
Pry.start
|
data/bin/setup
DELETED
data/esse.gemspec
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'lib/esse/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = 'esse'
|
7
|
-
spec.version = Esse::VERSION
|
8
|
-
spec.authors = ['Marcos G. Zimmermann']
|
9
|
-
spec.email = ['mgzmaster@gmail.com']
|
10
|
-
|
11
|
-
spec.summary = %[Pure Ruby toolkit based on official elasticsearch-ruby library. (No! It isn't a new DSL)]
|
12
|
-
spec.description = 'All the elegance of ruby with the elasticsearch flexibility. This gem is a pretty simple ' \
|
13
|
-
'but excential helpers to deal with mapping, indexing, serialization and search.'
|
14
|
-
spec.homepage = 'https://github.com/marcosgz/esse'
|
15
|
-
spec.license = 'MIT'
|
16
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
17
|
-
|
18
|
-
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
-
spec.metadata['source_code_uri'] = 'https://github.com/marcosgz/esse'
|
20
|
-
spec.metadata['changelog_uri'] = 'https://github.com/marcosgz/esse/blob/master/CHANGELOG.md'
|
21
|
-
|
22
|
-
# Specify which files should be added to the gem when it is released.
|
23
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
-
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
end
|
27
|
-
spec.bindir = 'exe'
|
28
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
-
spec.require_paths = ['lib']
|
30
|
-
|
31
|
-
spec.add_dependency 'elasticsearch'
|
32
|
-
spec.add_dependency 'multi_json'
|
33
|
-
spec.add_dependency 'thor', '>= 0.19'
|
34
|
-
spec.add_development_dependency 'dotenv'
|
35
|
-
spec.add_development_dependency 'awesome_print'
|
36
|
-
spec.add_development_dependency 'pry'
|
37
|
-
spec.add_development_dependency 'rake', '~> 12.3'
|
38
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
39
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class <%= @index_name %>::Serializers::<%= @type.camelize %>Serializer
|
4
|
-
def initialize(<%= @type %>, *_other)
|
5
|
-
@entity = <%= @type %>
|
6
|
-
end
|
7
|
-
|
8
|
-
def as_json
|
9
|
-
{
|
10
|
-
id: @entity.id, # This field is required
|
11
|
-
name: @entity.name,
|
12
|
-
}
|
13
|
-
end
|
14
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Esse
|
4
|
-
class IndexType
|
5
|
-
module ClassMethods
|
6
|
-
# Convert ruby object to json. Arguments will be same of passed through the
|
7
|
-
# collection. It's allowed a block or a class with the `as_json` instance method.
|
8
|
-
# Example with block
|
9
|
-
# serializer do |model, context = {}|
|
10
|
-
# {
|
11
|
-
# id: model.id,
|
12
|
-
# admin: context[:is_admin],
|
13
|
-
# }
|
14
|
-
# end
|
15
|
-
# Example with serializer class
|
16
|
-
# serializer UserSerializer
|
17
|
-
def serializer(klass = nil, &block)
|
18
|
-
if block_given?
|
19
|
-
@serializer_proc = block
|
20
|
-
elsif klass.is_a?(Class) && klass.instance_methods.include?(:as_json)
|
21
|
-
@serializer_proc = proc { |*args| klass.new(*args).as_json }
|
22
|
-
elsif klass.is_a?(Class) && klass.instance_methods.include?(:call)
|
23
|
-
@serializer_proc = proc { |*args| klass.new(*args).call }
|
24
|
-
else
|
25
|
-
msg = format('%<arg>p is not a valid serializer. The serializer should ' \
|
26
|
-
'respond with `as_json` instance method.', arg: klass,)
|
27
|
-
raise ArgumentError, msg
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def serialize(model, *args)
|
32
|
-
unless @serializer_proc
|
33
|
-
raise NotImplementedError, format('there is no serializer defined for the %<k>p index', k: to_s)
|
34
|
-
end
|
35
|
-
|
36
|
-
@serializer_proc.call(model, *args)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Used to define the source of data. A block is required. And its
|
40
|
-
# content should yield an array of each object that should be serialized.
|
41
|
-
# The list of arguments will be passed throught the serializer method.
|
42
|
-
#
|
43
|
-
# Here is an example of how this should work:
|
44
|
-
# collection do |conditions, &block|
|
45
|
-
# User.where(conditions).find_in_batches(batch_size: 5000) do |batch|
|
46
|
-
# block.call(batch, conditions)
|
47
|
-
# end
|
48
|
-
# end
|
49
|
-
def collection(&block)
|
50
|
-
raise(SyntaxError, 'No block given') unless block_given?
|
51
|
-
|
52
|
-
@collection_proc = block
|
53
|
-
end
|
54
|
-
|
55
|
-
# Used to fetch all batch of data defined on the collection model.
|
56
|
-
# Arguments can be anything. They will just be passed through the block.
|
57
|
-
# Useful when the collection depends on scope or any other conditions
|
58
|
-
# Example
|
59
|
-
# each_batch(active: true) do |data, _opts|
|
60
|
-
# puts data.size
|
61
|
-
# end
|
62
|
-
def each_batch(*args, &block)
|
63
|
-
unless @collection_proc
|
64
|
-
raise NotImplementedError, format('there is no collection defined for the %<k>p index', k: to_s)
|
65
|
-
end
|
66
|
-
|
67
|
-
@collection_proc.call(*args, &block)
|
68
|
-
rescue LocalJumpError
|
69
|
-
raise(SyntaxError, 'block must be explicitly declared in the collection definition')
|
70
|
-
end
|
71
|
-
|
72
|
-
# Wrap collection data into serialized batches
|
73
|
-
#
|
74
|
-
# @param [*Object] Any argument is allowed here. The collection will be called with same arguments.
|
75
|
-
# And the serializer will be initialized with those arguments too.
|
76
|
-
# @yield [Array, *Object] serialized collection and method arguments
|
77
|
-
def each_serialized_batch(*args, &block)
|
78
|
-
each_batch(*args) do |batch, *serializer_args|
|
79
|
-
entries = batch.map { |entry| serialize(entry, *serializer_args) }.compact
|
80
|
-
block.call(entries, *args)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
extend ClassMethods
|
86
|
-
end
|
87
|
-
end
|