Class: JayAPI::PropertiesFetcher

Inherits:
Object
  • Object
show all
Includes:
Elasticsearch::Time
Defined in:
lib/jay_api/properties_fetcher.rb

Overview

Fetches build properties from the provided information. ATTENTION: There’s a maximum number of data hashes that are returned (see MAX_SIZE).

Constant Summary collapse

MAX_SIZE =
100
BUILD_NAME_FIELD =

Name of the field used when querying the index for data using the name of the build job.

'build_properties.build_name.keyword'
BUILD_NUMBER_FIELD =
'build_properties.build_number'
VERSION_CODE_FIELD =

Name of the field used when querying the index for data using the version of the software.

'build_properties.version_code.keyword'
BUILD_RELEASE_FIELD =
'build_properties.build_release'
SUT_REVISION_FIELD =

Name of the field used when querying the index for data using the SUT Revision.

'sut_revision.keyword'
TIMESTAMP_FIELD =
'timestamp'

Constants included from Elasticsearch::Time

Elasticsearch::Time::TIME_FORMAT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Elasticsearch::Time

#format_time

Constructor Details

#initialize(index:) ⇒ PropertiesFetcher

Initializes a PropertiesFetcher object



35
36
37
# File 'lib/jay_api/properties_fetcher.rb', line 35

def initialize(index:)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



30
31
32
# File 'lib/jay_api/properties_fetcher.rb', line 30

def index
  @index
end

Instance Method Details

#after(timestamp) ⇒ JayAPI::PropertiesFetcher

Constraints the results to properties that were pushed after the given timestamp.



98
99
100
101
102
103
# File 'lib/jay_api/properties_fetcher.rb', line 98

def after(timestamp)
  # noinspection RubyMismatchedParameterType (checked by the if modifier)
  timestamp = format_time(timestamp) if timestamp.is_a?(Time)
  query_builder.query.bool.must.query_string(fields: TIMESTAMP_FIELD, query: "> \"#{timestamp}\"")
  self
end

#all {|Hash| ... } ⇒ Enumerator

Allows the caller to retrieve or iterate over the set of Build Properties entries. The method can be called with or without a block. If a block is given then each of the Build Properties entries will be yielded to the block, if no block is given then an Enumerator is returned.

Yields:

  • (Hash)

    One of the Build Properties entries.



166
167
168
# File 'lib/jay_api/properties_fetcher.rb', line 166

def all(&block)
  fetch_properties.all(&block)
end

#andJayAPI::PropertiesFetcher

This method is here only for readability. It is meant to act as a conjunction between two method calls.

Examples:

properties_fetcher.by_build_job('Release-XYZ01-Master').and.by_build_number(106)


125
126
127
# File 'lib/jay_api/properties_fetcher.rb', line 125

def and
  self
end

#before(timestamp) ⇒ JayAPI::PropertiesFetcher

Constraints the results to properties that were pushed before the given timestamp.



112
113
114
115
116
117
# File 'lib/jay_api/properties_fetcher.rb', line 112

def before(timestamp)
  # noinspection RubyMismatchedParameterType (checked by the if modifier)
  timestamp = format_time(timestamp) if timestamp.is_a?(Time)
  query_builder.query.bool.must.query_string(fields: TIMESTAMP_FIELD, query: "< \"#{timestamp}\"")
  self
end

#by_build_job(build_job) ⇒ JayAPI::PropertiesFetcher

Constraints the results to those properties belonging to the given build job



55
56
57
58
# File 'lib/jay_api/properties_fetcher.rb', line 55

def by_build_job(build_job)
  query_builder.query.bool.must.match_phrase(field: BUILD_NAME_FIELD, phrase: build_job)
  self
end

#by_build_number(build_number) ⇒ JayAPI::PropertiesFetcher

Constraints the results to those properties belonging to the given build number



65
66
67
68
# File 'lib/jay_api/properties_fetcher.rb', line 65

def by_build_number(build_number)
  query_builder.query.bool.must.query_string(fields: BUILD_NUMBER_FIELD, query: build_number)
  self
end

#by_release_tag(release_tag) ⇒ JayAPI::PropertiesFetcher

Constraint the results to properties that belong or don’t belong to (depending on the release_tag parameter) a release build.



86
87
88
89
# File 'lib/jay_api/properties_fetcher.rb', line 86

def by_release_tag(release_tag)
  query_builder.query.bool.must.query_string(fields: BUILD_RELEASE_FIELD, query: release_tag)
  self
end

#by_software_version(software_version) ⇒ JayAPI::PropertiesFetcher

Constraints the results to those properties for which the software version matches the given one.



75
76
77
78
# File 'lib/jay_api/properties_fetcher.rb', line 75

def by_software_version(software_version)
  query_builder.query.bool.must.match_phrase(field: VERSION_CODE_FIELD, phrase: software_version)
  self
end

#by_sut_revision(sut_revision) ⇒ JayAPI::PropertiesFetcher

Constraints the results to those properties belonging to the given SUT Revision.



44
45
46
47
# File 'lib/jay_api/properties_fetcher.rb', line 44

def by_sut_revision(sut_revision)
  query_builder.query.bool.must.match_phrase(field: SUT_REVISION_FIELD, phrase: sut_revision)
  self
end

#firstHash?



138
139
140
141
# File 'lib/jay_api/properties_fetcher.rb', line 138

def first
  sort_records('asc').size(1)
  fetch_properties.first
end

#lastHash?



131
132
133
134
# File 'lib/jay_api/properties_fetcher.rb', line 131

def last
  sort_records('desc').size(1)
  fetch_properties.last
end

#limit(size) ⇒ JayAPI::PropertiesFetcher Also known as: size

Limits the amount of records returned to the given number.



148
149
150
151
152
153
# File 'lib/jay_api/properties_fetcher.rb', line 148

def limit(size)
  size = [size, MAX_SIZE].min
  # noinspection RubyMismatchedParameterType (The array will never be empty)
  query_builder.size(size)
  self
end