Class: JayAPI::PriorVersionFetcherBase

Inherits:
Object
  • Object
show all
Defined in:
lib/jay_api/prior_version_fetcher_base.rb

Overview

Fetches the previous software version depending on the given version.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, index_name:) ⇒ PriorVersionFetcherBase

Returns a new instance of PriorVersionFetcherBase.

Parameters:

  • client (JayAPI::Elasticsearch::Client)

    The Client object to use when connecting to Elasticsearch to execute queries.

  • index_name (String)

    The index of the build properties in Jay



15
16
17
18
# File 'lib/jay_api/prior_version_fetcher_base.rb', line 15

def initialize(client:, index_name:)
  @client = client
  @index_name = index_name
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



10
11
12
# File 'lib/jay_api/prior_version_fetcher_base.rb', line 10

def client
  @client
end

Instance Method Details

#prior_version(current_version:) ⇒ String?

Calculates the prior software version given the current version if it exists.

Parameters:

  • current_version (String)

    The version for which to find a prior version.

Returns:

  • (String, nil)

    the previous software version or nil if none is existent.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jay_api/prior_version_fetcher_base.rb', line 26

def prior_version(current_version:)
  versions = []
  results = index_obj.search(query)

  results.all do |document|
    # Since the version is inside an array we have to call first
    versions << document['fields']['build_properties.version_code.keyword'].first
  end

  # This function must be injected by the project-specific fetcher
  compute_last_version(current_version: current_version, existent_versions: versions)
end