search_flip 4.0.0.beta14 → 4.0.0.beta15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a711d443c26f483da4898b2b7e69d1ca7c2dfd1280cd4d0a7d8ae6affbcdbc0d
4
- data.tar.gz: a5721bc56cc311ce664f49d89229b79fdfe525357c33b6ff9b46e5c7bc6e634f
3
+ metadata.gz: cbf6d1f0c653af6bc398768eff11d7715c1cea101a06f4eefb1c6078ad33abc1
4
+ data.tar.gz: c2568175d32374201ea212abfdebd709d8933c92c19cc646225b7bd90244498c
5
5
  SHA512:
6
- metadata.gz: 43c8b33aaa23e84e65b93a624806664c7f7ea779e582ba010b21319ea8b597c4b53633edf9f6746762b2dce844a0ad0764fc1c2209fdee2ab19aea60a7dbbad4
7
- data.tar.gz: 22c06e14023d4bd43475f3573b1e387bb855e43fdb0babc9b366e0f7388ecde08eaee53598d0dda148ecf1f62afb5ed0b328f91742471e7bd8f3e5c7349df146
6
+ metadata.gz: 3f28cc23ad081e6345764799b2f70b957c9be97fab7781f22fbee580ed2c28b8da0bb0b3a9c4ef5d4ec200c94a6799a5c082489d9a62b2e24f94c49e29bcd4d1
7
+ data.tar.gz: 1f773fcf838215595db93760a66359acf77a19f63758447a9f30498be90dcce079a2ba21e2ce3350f2b6295e3906b3bb3ea3b5472f0804965b6003e61d94460d
@@ -39,6 +39,10 @@ jobs:
39
39
  env:
40
40
  discovery.type: single-node
41
41
  plugins.security.disabled: true
42
+ - image: opensearchproject/opensearch:2.13.0
43
+ env:
44
+ discovery.type: single-node
45
+ DISABLE_SECURITY_PLUGIN: true
42
46
  ruby:
43
47
  - 2.7
44
48
  - 3.0
data/CHANGELOG.md CHANGED
@@ -11,7 +11,20 @@
11
11
  * Added `SearchFlip::Connection#get_cluster_settings` and
12
12
  `#update_cluster_settings`
13
13
 
14
- ## v3.8.0.
14
+ ## v3.9.0
15
+
16
+ * Allow to configure the elasticsearch version no matter which elasticsearch
17
+ version is actually in use. The version information is needed to support
18
+ version dependent features. Please note that manually configuring the version
19
+ is usually not need as the version by default is determined by sending one
20
+ request to elasticsearch.
21
+
22
+ ```ruby
23
+ SearchFlip::Config[:version] = { number: "8.1.1" }
24
+ SearchFlip::Config[:version] = { number: "2.13", distribution: "opensearch" }
25
+ ```
26
+
27
+ ## v3.8.0
15
28
 
16
29
  * Support Opensearch 1.x and 2.x
17
30
 
data/Gemfile CHANGED
@@ -14,6 +14,6 @@ gem "factory_bot"
14
14
  gem "rake"
15
15
  gem "rspec"
16
16
  gem "rubocop"
17
- gem "sqlite3"
17
+ gem "sqlite3", "~> 1.4"
18
18
  gem "timecop"
19
19
  gem "webmock"
data/README.md CHANGED
@@ -98,6 +98,16 @@ Available config options are:
98
98
  * `auto_refresh` tells SearchFlip to automatically refresh an index after
99
99
  import, index, delete, etc operations. This is e.g. useful for testing, etc.
100
100
  Defaults to false.
101
+ * `version` allows to configure the elasticsearch version no matter which
102
+ elasticsearch version is actually in use. The version information is needed to
103
+ support version dependent features. Please note that manually configuring the
104
+ version is usually not need as the version by default is determined by sending
105
+ one request to elasticsearch.
106
+
107
+ ```ruby
108
+ SearchFlip::Config[:version] = { number: "8.1.1" }
109
+ SearchFlip::Config[:version] = { number: "2.13", distribution: "opensearch" }
110
+ ```
101
111
 
102
112
  ## Usage
103
113
 
@@ -26,7 +26,7 @@ module SearchFlip
26
26
  # @return [String] The Elasticsearch distribution
27
27
 
28
28
  def distribution
29
- @distribution ||= SearchFlip::JSON.parse(version_response.to_s)["version"]["distribution"]
29
+ @distribution ||= SearchFlip::Config.dig(:version, :distribution) || SearchFlip::JSON.parse(version_response.to_s)["version"]["distribution"]
30
30
  end
31
31
 
32
32
  # Queries the cluster settings from Elasticsearch
@@ -66,7 +66,7 @@ module SearchFlip
66
66
  # @return [String] The Elasticsearch version
67
67
 
68
68
  def version
69
- @version ||= SearchFlip::JSON.parse(version_response.to_s)["version"]["number"]
69
+ @version ||= SearchFlip::Config.dig(:version, :number) || SearchFlip::JSON.parse(version_response.to_s)["version"]["number"]
70
70
  end
71
71
 
72
72
  # Queries and returns the Elasticsearch cluster health.
@@ -5,7 +5,7 @@ module SearchFlip
5
5
  end
6
6
 
7
7
  def self.parse(json)
8
- ::JSON.parse(json)
8
+ ::JSON.parse(json, object_class: SearchFlip::Result)
9
9
  end
10
10
  end
11
11
  end
@@ -305,11 +305,11 @@ module SearchFlip
305
305
  if response["aggregations"].nil? || response["aggregations"][key].nil?
306
306
  SearchFlip::Result.new
307
307
  elsif response["aggregations"][key]["buckets"].is_a?(Array)
308
- response["aggregations"][key]["buckets"].each_with_object({}) { |bucket, hash| hash[bucket["key"]] = SearchFlip::Result.convert(bucket) }
308
+ response["aggregations"][key]["buckets"].each_with_object({}) { |bucket, hash| hash[bucket["key"]] = bucket }
309
309
  elsif response["aggregations"][key]["buckets"].is_a?(Hash)
310
- SearchFlip::Result.convert(response["aggregations"][key]["buckets"])
310
+ response["aggregations"][key]["buckets"]
311
311
  else
312
- SearchFlip::Result.convert(response["aggregations"][key])
312
+ response["aggregations"][key]
313
313
  end
314
314
  end
315
315
  end
@@ -8,32 +8,6 @@ module SearchFlip
8
8
  # result.some_key # => "value"
9
9
 
10
10
  class Result < Hash
11
- def self.convert(hash)
12
- res = self[hash]
13
-
14
- res.each do |key, value|
15
- if value.is_a?(Hash)
16
- res[key] = convert(value)
17
- elsif value.is_a?(Array)
18
- res[key] = convert_array(value)
19
- end
20
- end
21
-
22
- res
23
- end
24
-
25
- def self.convert_array(arr)
26
- arr.map do |obj|
27
- if obj.is_a?(Hash)
28
- convert(obj)
29
- elsif obj.is_a?(Array)
30
- convert_array(obj)
31
- else
32
- obj
33
- end
34
- end
35
- end
36
-
37
11
  def method_missing(name, *args, &block)
38
12
  self[name.to_s]
39
13
  end
@@ -43,8 +17,8 @@ module SearchFlip
43
17
  end
44
18
 
45
19
  def self.from_hit(hit)
46
- res = convert(hit["_source"] || {})
47
- res["_hit"] = convert(self[hit].tap { |hash| hash.delete("_source") })
20
+ res = self[hit["_source"] || {}]
21
+ res["_hit"] = self[hit].tap { |hash| hash.delete("_source") }
48
22
  res
49
23
  end
50
24
  end
@@ -1,3 +1,3 @@
1
1
  module SearchFlip
2
- VERSION = "4.0.0.beta14"
2
+ VERSION = "4.0.0.beta15"
3
3
  end
@@ -5,12 +5,28 @@ RSpec.describe SearchFlip::Connection do
5
5
  it "reutrns the distribution" do
6
6
  expect([nil, "opensearch"]).to include(SearchFlip::Connection.new.distribution)
7
7
  end
8
+
9
+ it "returns the distribution from the config when given" do
10
+ SearchFlip::Config[:version] = { distribution: "distribution" }
11
+
12
+ expect(SearchFlip::Connection.new.distribution).to eq("distribution")
13
+ ensure
14
+ SearchFlip::Config.delete(:version)
15
+ end
8
16
  end
9
17
 
10
18
  describe "#version" do
11
19
  it "returns the version" do
12
20
  expect(SearchFlip::Connection.new.version).to match(/\A[0-9.]+\z/)
13
21
  end
22
+
23
+ it "returns the version from the config when given" do
24
+ SearchFlip::Config[:version] = { number: "1.2.3" }
25
+
26
+ expect(SearchFlip::Connection.new.version).to eq("1.2.3")
27
+ ensure
28
+ SearchFlip::Config.delete(:version)
29
+ end
14
30
  end
15
31
 
16
32
  describe "#cluster_health" do
@@ -39,7 +39,7 @@ RSpec.describe SearchFlip::JSON do
39
39
 
40
40
  described_class.parse(payload)
41
41
 
42
- expect(JSON).to have_received(:parse).with(payload)
42
+ expect(JSON).to have_received(:parse).with(payload, object_class: SearchFlip::Result)
43
43
  end
44
44
  end
45
45
  end
@@ -1,26 +1,17 @@
1
1
  require File.expand_path("../spec_helper", __dir__)
2
2
 
3
3
  RSpec.describe SearchFlip::Result do
4
- describe ".convert" do
5
- it "deeply converts hashes and arrays" do
6
- result = described_class.convert("parent" => { "child" => [{ "key1" => "value" }, { "key2" => 3 }] })
7
-
8
- expect(result.parent.child[0].key1).to eq("value")
9
- expect(result.parent.child[1].key2).to eq(3)
10
- end
11
- end
12
-
13
4
  describe "#method_missing" do
14
5
  it "returns the value of the key equal to the message name" do
15
- expect(described_class.convert("some_key" => "value").some_key).to eq("value")
6
+ expect(described_class["some_key" => "value"].some_key).to eq("value")
16
7
  expect(described_class.new.some_key).to be_nil
17
8
  end
18
9
  end
19
10
 
20
11
  describe "#responds_to_missing?" do
21
12
  it "returns true/false if the key equal to the message name is present or not" do
22
- expect(described_class.convert("some_key" => nil).respond_to?(:some_key)).to eq(true)
23
- expect(described_class.convert("some_key" => nil).respond_to?(:other_key)).to eq(false)
13
+ expect(described_class["some_key" => nil].respond_to?(:some_key)).to eq(true)
14
+ expect(described_class["some_key" => nil].respond_to?(:other_key)).to eq(false)
24
15
  end
25
16
  end
26
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_flip
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.beta14
4
+ version: 4.0.0.beta15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Vetter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-19 00:00:00.000000000 Z
11
+ date: 2024-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http