elasticsearch-rails 8.0.0.pre → 8.0.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
2
  SHA256:
3
- metadata.gz: 64ebf5844db4e95b8dfe3713ca0059c700d6a75907f96de772f0446c07e4f5da
4
- data.tar.gz: 290065237c0e894f0d905b2f74a867fb8a2fff13cd6a0c9f7bbe3a0a5681382f
3
+ metadata.gz: feb6cc50443134d9f6bc424aee2e46edd208f111d98b66e0bcba2c13eed8905f
4
+ data.tar.gz: bc01ddaec5725cc35431e89318eef5d021c8eadb12fe6ae047419adaec82e9d2
5
5
  SHA512:
6
- metadata.gz: d3e5e62c7a52f4bd25ea892f3336f9b27d66b04a1599cab018e44565b594b562a5fb906234cacc23b7eb6898455f1c2f6064737493754c4c779059d997467ef4
7
- data.tar.gz: 2c02e8ba745189d9d38996d4b5d6dc25de0b45cbe00cde33a37fc6cca033404e5a81d67f2ea77a9c62c66864cc6cee8542214a9ead2f51378be7995a0d05546f
6
+ metadata.gz: daba8716f145f0b4ffbb953832eff315c3c09821a1439923fbc9ed8ac7d3e3bd2c6e9dc0a3e37f97b355d2bac828329ef0ee3b23786977d9c96117faed92ab87
7
+ data.tar.gz: d7956874bf60225e7d6d2d520951b446feb32b1b184836e86b8a04592c4d860cedbfd604be143a57d1afaf8be26118ae91dc4c6abf091a409a6556706ffa6a98
data/Gemfile CHANGED
@@ -32,7 +32,7 @@ group :development, :testing do
32
32
  gem 'pry-nav'
33
33
  gem 'rspec'
34
34
  unless defined?(JRUBY_VERSION)
35
- gem 'sqlite3'
35
+ gem 'sqlite3', '~> 1.4'
36
36
  gem 'debug'
37
37
  end
38
38
  end
data/README.md CHANGED
@@ -6,18 +6,19 @@ library, providing features suitable for Ruby on Rails applications.
6
6
 
7
7
  ## Compatibility
8
8
 
9
- This library is compatible with Ruby 1.9.3 and higher.
9
+ This library is compatible with Ruby 3.1 and higher.
10
10
 
11
- The version numbers follow the Elasticsearch major versions. Currently the `main` branch is compatible with version `7.x` of the Elasticsearch stack. **We haven't tested and updated the code for Elasticsearch `8.0` yet**.
11
+ The version numbers follow the Elasticsearch major versions. Currently the `main` branch is compatible with version `8.x` of the Elasticsearch stack.
12
12
 
13
- | Rubygem | | Elasticsearch |
14
- |:-------------:|:-:| :-----------: |
15
- | 0.1 | → | 1.x |
16
- | 2.x | → | 2.x |
17
- | 5.x | → | 5.x |
18
- | 6.x | → | 6.x |
19
- | 7.x | → | 7.x |
20
- | main | → | 7.x |
13
+ | Rubygem | | Elasticsearch |
14
+ |:-------:|:-:|:-------------:|
15
+ | 0.1 | → | 1.x |
16
+ | 2.x | → | 2.x |
17
+ | 5.x | → | 5.x |
18
+ | 6.x | → | 6.x |
19
+ | 7.x | → | 7.x |
20
+ | 8.x | → | 8.x |
21
+ | main | → | 8.x |
21
22
 
22
23
  ## Installation
23
24
 
@@ -137,9 +138,9 @@ This software is licensed under the Apache 2 license, quoted below.
137
138
  the Apache License, Version 2.0 (the "License"); you may
138
139
  not use this file except in compliance with the License.
139
140
  You may obtain a copy of the License at
140
-
141
+
141
142
  http://www.apache.org/licenses/LICENSE-2.0
142
-
143
+
143
144
  Unless required by applicable law or agreed to in writing,
144
145
  software distributed under the License is distributed on an
145
146
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -46,8 +46,19 @@ module Elasticsearch
46
46
  payload = event.payload
47
47
  name = "#{payload[:klass]} #{payload[:name]} (#{event.duration.round(1)}ms)"
48
48
  search = payload[:search].inspect.gsub(/:(\w+)=>/, '\1: ')
49
+ debug %Q| #{color(name, GREEN, color_option(true))} #{colorize_logging ? "\e[2m#{search}\e[0m" : search}|
50
+ end
51
+
52
+ private
53
+
54
+ def color_option(bold_value)
55
+ new_color_syntax? ? { bold: bold_value } : bold_value
56
+ end
57
+
58
+ def new_color_syntax?
59
+ return @new_color_syntax if defined?(@new_color_syntax)
49
60
 
50
- debug %Q| #{color(name, GREEN, true)} #{colorize_logging ? "\e[2m#{search}\e[0m" : search}|
61
+ @new_color_syntax = ::Rails.respond_to?(:gem_version) && ::Rails.gem_version >= '7.1'
51
62
  end
52
63
  end
53
64
 
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Elasticsearch
19
19
  module Rails
20
- VERSION = '8.0.0.pre'.freeze
20
+ VERSION = '8.0.0'.freeze
21
21
  end
22
22
  end
@@ -0,0 +1,57 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ require 'spec_helper'
19
+ require 'elasticsearch/rails/instrumentation/log_subscriber'
20
+
21
+ describe Elasticsearch::Rails::Instrumentation::LogSubscriber do
22
+ subject(:instance) { described_class.new }
23
+
24
+ let(:logger) { instance_double(Logger) }
25
+
26
+ before do
27
+ allow(instance).to receive(:logger) { logger }
28
+ end
29
+
30
+ describe "#search" do
31
+ subject { instance.search(event) }
32
+
33
+ let(:event) { double("search.elasticsearch", duration: 1.2345, payload: { name: "execute", search: { query: { match_all: {}}}}) }
34
+
35
+ it "logs the event" do
36
+ expect(instance).to receive(:color).with(" execute (1.2ms)", described_class::GREEN, { bold: true }).and_call_original
37
+ expect(logger).to receive(:debug?) { true }
38
+ expect(logger).to receive(:debug).with(" \e[1m\e[32m execute (1.2ms)\e[0m \e[2m{query: {match_all: {}}}\e[0m")
39
+ subject
40
+ end
41
+
42
+ context "when Rails version is older" do
43
+ let(:rails_version) { "7.0.0" }
44
+
45
+ before do
46
+ allow(::Rails).to receive(:gem_version) { Gem::Version.new(rails_version) }
47
+ end
48
+
49
+ it "logs the event" do
50
+ expect(instance).to receive(:color).with(" execute (1.2ms)", described_class::GREEN, true).and_call_original
51
+ expect(logger).to receive(:debug?) { true }
52
+ expect(logger).to receive(:debug).with(" \e[1m\e[32m execute (1.2ms)\e[0m \e[2m{query: {match_all: {}}}\e[0m")
53
+ subject
54
+ end
55
+ end
56
+ end
57
+ end
data/spec/spec_helper.rb CHANGED
@@ -20,6 +20,7 @@ require 'active_record'
20
20
  require 'elasticsearch/model'
21
21
  require 'elasticsearch/rails'
22
22
  require 'rails/railtie'
23
+ require 'rails/version'
23
24
  require 'elasticsearch/rails/instrumentation'
24
25
 
25
26
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.0.pre
4
+ version: 8.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic Client Library Maintainers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-16 00:00:00.000000000 Z
11
+ date: 2024-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -275,6 +275,7 @@ files:
275
275
  - lib/rails/templates/searchable.dsl.rb
276
276
  - lib/rails/templates/searchable.rb
277
277
  - lib/rails/templates/seeds.rb
278
+ - spec/instrumentation/log_subscriber_spec.rb
278
279
  - spec/instrumentation_spec.rb
279
280
  - spec/lograge_spec.rb
280
281
  - spec/spec_helper.rb
@@ -302,11 +303,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
302
303
  - !ruby/object:Gem::Version
303
304
  version: '0'
304
305
  requirements: []
305
- rubygems_version: 3.5.3
306
+ rubygems_version: 3.5.9
306
307
  signing_key:
307
308
  specification_version: 4
308
309
  summary: Ruby on Rails integrations for Elasticsearch.
309
310
  test_files:
311
+ - spec/instrumentation/log_subscriber_spec.rb
310
312
  - spec/instrumentation_spec.rb
311
313
  - spec/lograge_spec.rb
312
314
  - spec/spec_helper.rb