jay_api 27.2.1 → 27.4.0

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: a35b06322adf0ab11fcdd970835c9a1aac3ff8b5de340c4daa8fe9d2214613a5
4
- data.tar.gz: 0be3fa8509779e0d18e4cacc5df1a182babe20554568f6a1af43ca9c8af2cc8e
3
+ metadata.gz: 5a6edc53b541759520ecc03ea41bd03119d4c89aca3967d6a108d7b4329d31ac
4
+ data.tar.gz: 576525ff4b4a470f1b81839990344837f6907bd3d0e54acd9dab7ccff7090dce
5
5
  SHA512:
6
- metadata.gz: 85f9eac9b429ef76ab803704be715bb038860a789376cd42dd213bd3d1fbcfaac2fc89881d3419a721ce3e3a25614a1f042067282c8a448c4c1664ca99ff381a
7
- data.tar.gz: c01b9deda5d00aec9a188e7e60fd4b9b6d3f82801750cb5e00d9339c4380822b8e08788e9080107cb67cb26d1c80c4e8c42f99b68b1ef04a7e758c94c0561b31
6
+ metadata.gz: 54bf37bfd8b82a8337645a8064b2cc82707d8c985816646ae23774b917676b7a79642710420dba680cb163491fb8035eaed603ac22c86410c63e43907805a14d
7
+ data.tar.gz: 4525bc1fb75c38f6e741e245757e3261c9bf4a0981d1e65da3756c65f24610ac66d25480a6d842f54c5c9097fad6612e05736310226466ddd783df13b142266f
data/CHANGELOG.md CHANGED
@@ -8,6 +8,22 @@ Please mark backwards incompatible changes with an exclamation mark at the start
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [27.4.0] - 2025-04-10
12
+
13
+ ### Added
14
+ - The `#ping` method to `Elasticsearch::Client`
15
+
16
+ ## [27.3.0] - 2025-04-04
17
+
18
+ ### Added
19
+ - The `Aggregations::Cardinality` class and the `Aggregations#cardinality`
20
+ method. They make it possible to use Elasticsearch's `cardinality`
21
+ aggregations.
22
+
23
+ ### Changed
24
+ - `GitilesHelper#gitiles_url` can now be called without a `path`. When no path
25
+ is given the method generates a link to the given `refspec` instead.
26
+
11
27
  ## [27.2.1] - 2025-03-14
12
28
 
13
29
  ### Fixed
@@ -3,6 +3,7 @@
3
3
  require 'elasticsearch/api/namespace/tasks'
4
4
  require 'elasticsearch/transport/transport/errors'
5
5
  require 'faraday/error'
6
+ require 'forwardable'
6
7
 
7
8
  require_relative '../abstract/connection'
8
9
 
@@ -13,6 +14,8 @@ module JayAPI
13
14
  # rescue the error up to a few times and re-try the connection. This way the
14
15
  # connection to Elasticsearch will be more robust.
15
16
  class Client
17
+ extend Forwardable
18
+
16
19
  # The errors that, if raised, must cause a retry of the connection.
17
20
  ERRORS = [
18
21
  ::Elasticsearch::Transport::Transport::ServerError,
@@ -33,6 +36,11 @@ module JayAPI
33
36
 
34
37
  attr_reader :transport_client, :logger, :max_attempts, :wait_strategy
35
38
 
39
+ # @return [Boolean] True if there is connectivity to the cluster, false otherwise.
40
+ # @raise [Transport::Errors::Forbidden] If the user has no permissions to
41
+ # ping the cluster.
42
+ def_delegator :transport_client, :ping
43
+
36
44
  # @param [Elasticsearch::Transport::Client] transport_client The Client
37
45
  # object that will be wrapped.
38
46
  # @param [Logging::Logger] logger
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'aggregation'
4
+
5
+ module JayAPI
6
+ module Elasticsearch
7
+ class QueryBuilder
8
+ class Aggregations
9
+ # Represents a +cardinality+ aggregation in Elasticsearch.
10
+ # Information on this type of aggregation can be found here:
11
+ # https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
12
+ class Cardinality < ::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Aggregation
13
+ attr_reader :field
14
+
15
+ # @param [String] name The name used by Elasticsearch to identify each
16
+ # of the aggregations.
17
+ # @param [String] field The field whose cardinality (number of unique
18
+ # values) should be calculated.
19
+ def initialize(name, field:)
20
+ super(name)
21
+
22
+ @field = field
23
+ end
24
+
25
+ # @raise [JayAPI::Elasticsearch::QueryBuilder::Aggregations::Errors::AggregationsError]
26
+ # Is always raised. The Cardinality aggregation cannot have nested
27
+ # aggregations.
28
+ def aggs
29
+ no_nested_aggregations('Cardinality')
30
+ end
31
+
32
+ # @return [self] A copy of the receiver.
33
+ def clone
34
+ self.class.new(name, field: field)
35
+ end
36
+
37
+ # @return [Hash] The Hash representation of the +Aggregation+.
38
+ # Properly formatted for Elasticsearch.
39
+ def to_h
40
+ super do
41
+ {
42
+ cardinality: {
43
+ field: field
44
+ }
45
+ }
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -4,6 +4,7 @@ require 'forwardable'
4
4
 
5
5
  require_relative 'aggregations/aggregation'
6
6
  require_relative 'aggregations/avg'
7
+ require_relative 'aggregations/cardinality'
7
8
  require_relative 'aggregations/filter'
8
9
  require_relative 'aggregations/scripted_metric'
9
10
  require_relative 'aggregations/sum'
@@ -99,6 +100,16 @@ module JayAPI
99
100
  add(::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Filter.new(name, &block))
100
101
  end
101
102
 
103
+ # Adds a +cardinality+ type aggregation. For more information about the parameters
104
+ # @see JayAPI::Elasticsearch::QueryBuilder::Aggregations::Cardinality#initialize
105
+ def cardinality(name, field:)
106
+ add(
107
+ ::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Cardinality.new(
108
+ name, field: field
109
+ )
110
+ )
111
+ end
112
+
102
113
  # Returns a Hash with the correct format for the current list of
103
114
  # aggregations. For example:
104
115
  #
@@ -8,16 +8,18 @@ module JayAPI
8
8
  # Offers a set of utility methods to work with Gerrit's Gitiles URLs.
9
9
  module GitilesHelper
10
10
  GITILES_PATH = '/plugins/gitiles/'
11
- GITILES_REFSPEC = '/+/%<refspec>s/'
11
+ GITILES_REFSPEC = '/+/%<refspec>s'
12
12
 
13
13
  # Returns a Gitiles URL for the given parameters
14
14
  # @param [String] repository The URL of the git repository.
15
- # @param [String] refspec The name of a branch or the SHA1 of a particular
16
- # commit.
17
- # @param [String] path The path to the source file.
18
- # @param [Integer, String] line_number The line number
15
+ # @param [String] refspec The name of a branch or the SHA1 of a
16
+ # particular commit.
17
+ # @param [String, nil] path The path to the source file. If +nil+ is
18
+ # given a link to the +refspec+ itself is will be created.
19
+ # @param [Integer, String, nil] line_number The line number. Ignored
20
+ # when +path+ is +nil+.
19
21
  # @return [String] The corresponding Gitiles URL.
20
- def gitiles_url(repository:, refspec:, path:, line_number: nil)
22
+ def gitiles_url(repository:, refspec:, path: nil, line_number: nil)
21
23
  # NOTE: Here File.join is being used because it takes care of cases in
22
24
  # which both strings have slash (/) at their tips and removes the double
23
25
  # slash, for example:
@@ -30,14 +32,15 @@ module JayAPI
30
32
  #
31
33
  # URI.join('https://www.example.com/hello/world', '/again') => https://www.example.com/again
32
34
 
33
- @gitiles_urls ||= {}
34
- base_url = @gitiles_urls[repository] ||= translate_gerrit_url(repository)
35
+ fragments = [
36
+ gerrit_urls_cache[repository] ||= translate_gerrit_url(repository),
37
+ format(GITILES_REFSPEC, refspec: refspec)
38
+ ]
35
39
 
36
- File.join(
37
- base_url,
38
- format(GITILES_REFSPEC, refspec: refspec),
39
- [path, line_number].compact.join('#') # If there is no line number the # will not appear in the URL
40
- )
40
+ # If there is no line number the # will not appear in the URL
41
+ fragments << [path, line_number].compact.join('#') if path
42
+
43
+ File.join(*fragments)
41
44
  end
42
45
 
43
46
  # Translates a Gerrit repository URL into a Gerrit Gitiles URL for that
@@ -52,6 +55,15 @@ module JayAPI
52
55
  path = uri.path.sub(%r{^/a/}, '/') # Removes the /a/ at the beginning of HTTP/S repository URLs
53
56
  URI::HTTPS.build(host: uri.host, path: File.join(GITILES_PATH, path)).to_s
54
57
  end
58
+
59
+ private
60
+
61
+ # @return [Hash{String => String}] A Hash that act as a cache for URLs
62
+ # generated by #translate_gerrit_url. It is used to avoid having to
63
+ # translate the same repository's URL multiple times.
64
+ def gerrit_urls_cache
65
+ @gerrit_urls_cache ||= {}
66
+ end
55
67
  end
56
68
  end
57
69
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module JayAPI
4
4
  # JayAPI gem's semantic version
5
- VERSION = '27.2.1'
5
+ VERSION = '27.4.0'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jay_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 27.2.1
4
+ version: 27.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Accenture-Industry X
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-03-14 00:00:00.000000000 Z
12
+ date: 2025-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -139,6 +139,7 @@ files:
139
139
  - lib/jay_api/elasticsearch/query_builder/aggregations.rb
140
140
  - lib/jay_api/elasticsearch/query_builder/aggregations/aggregation.rb
141
141
  - lib/jay_api/elasticsearch/query_builder/aggregations/avg.rb
142
+ - lib/jay_api/elasticsearch/query_builder/aggregations/cardinality.rb
142
143
  - lib/jay_api/elasticsearch/query_builder/aggregations/errors.rb
143
144
  - lib/jay_api/elasticsearch/query_builder/aggregations/errors/aggregations_error.rb
144
145
  - lib/jay_api/elasticsearch/query_builder/aggregations/filter.rb