jay_api 27.2.1 → 27.3.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: 7bf95eb5af7069c36512de16c021bbd88e338bdd3edc80bd195ba2f06d780d84
4
+ data.tar.gz: 73c1fd90f8fafbad98bb24a0afce1024f17114ab720c3c94bdb11d484ca686fb
5
5
  SHA512:
6
- metadata.gz: 85f9eac9b429ef76ab803704be715bb038860a789376cd42dd213bd3d1fbcfaac2fc89881d3419a721ce3e3a25614a1f042067282c8a448c4c1664ca99ff381a
7
- data.tar.gz: c01b9deda5d00aec9a188e7e60fd4b9b6d3f82801750cb5e00d9339c4380822b8e08788e9080107cb67cb26d1c80c4e8c42f99b68b1ef04a7e758c94c0561b31
6
+ metadata.gz: c47ee03a8915dd5a328d6717ef90bd32a0cef9a588b428801e542271814fffa497ce0f6b037b8a30a3729156446aac0c01e8696bab269fb49fa54c90aaa6cb32
7
+ data.tar.gz: 3e1fdfbdff8c7318c0632b49ebc77575a859e263ea0ccaa800bdfbc397f7ff6498ec899052b8270f58e660137b1cb57dae0c71422ade417cd64dd24a765ef50d
data/CHANGELOG.md CHANGED
@@ -8,6 +8,17 @@ Please mark backwards incompatible changes with an exclamation mark at the start
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [27.3.0] - 2025-04-04
12
+
13
+ ### Added
14
+ - The `Aggregations::Cardinality` class and the `Aggregations#cardinality`
15
+ method. They make it possible to use Elasticsearch's `cardinality`
16
+ aggregations.
17
+
18
+ ### Changed
19
+ - `GitilesHelper#gitiles_url` can now be called without a `path`. When no path
20
+ is given the method generates a link to the given `refspec` instead.
21
+
11
22
  ## [27.2.1] - 2025-03-14
12
23
 
13
24
  ### Fixed
@@ -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.3.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.3.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-04 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