Class: PactBroker::Matrix::ResolvedSelector
- Inherits:
-
Hash
- Object
- Hash
- PactBroker::Matrix::ResolvedSelector
- Defined in:
- lib/pact_broker/matrix/resolved_selector.rb
Constant Summary collapse
- NULL_VERSION_ID =
A version ID of -1 will not match any rows, which is what we want to ensure that no matrix rows are returned for a version that does not exist.
-1
- NULL_PACTICIPANT_ID =
-1
Class Method Summary collapse
- .for_non_existing_pacticipant(original_selector, type, ignore) ⇒ Object
- .for_pacticipant(pacticipant, original_selector, type, ignore) ⇒ Object
-
.for_pacticipant_and_non_existing_version(pacticipant, original_selector, type, ignore) ⇒ Object
rubocop: enable Metrics/ParameterLists.
-
.for_pacticipant_and_version(pacticipant, version, original_selector, type, ignore, one_of_many = false) ⇒ Object
rubocop: disable Metrics/ParameterLists.
Instance Method Summary collapse
- #branch ⇒ Object
- #consider? ⇒ Boolean
-
#description ⇒ Object
rubocop: disable Metrics/CyclomaticComplexity.
- #environment_name ⇒ Object
- #ignore? ⇒ Boolean
-
#inferred? ⇒ Boolean
Was this selector inferred based on the user’s query? (ie. the integrations were calculated because only one selector was specified).
-
#initialize(params = {}) ⇒ ResolvedSelector
constructor
A new instance of ResolvedSelector.
- #latest? ⇒ Boolean
- #latest_from_branch? ⇒ Boolean
- #latest_tagged? ⇒ Boolean
- #latest_tagged_version_that_does_not_exist? ⇒ Boolean
- #most_specific_criterion ⇒ Object
- #one_of_many? ⇒ Boolean
- #only_pacticipant_name_specified? ⇒ Boolean
- #pacticipant_does_not_exist? ⇒ Boolean
- #pacticipant_id ⇒ Object
- #pacticipant_name ⇒ Object
- #pacticipant_or_version_does_not_exist? ⇒ Boolean
- #pacticipant_version_id ⇒ Object
- #pacticipant_version_number ⇒ Object
- #pacticipant_version_specified_in_original_selector? ⇒ Boolean
-
#specified? ⇒ Boolean
Did the user specify this selector in the user’s query?.
- #specified_version_that_does_not_exist? ⇒ Boolean
- #tag ⇒ Object
- #version_does_not_exist? ⇒ Boolean
- #version_exists? ⇒ Boolean
Constructor Details
#initialize(params = {}) ⇒ ResolvedSelector
Returns a new instance of ResolvedSelector.
15 16 17 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 15 def initialize(params = {}) merge!(params) end |
Class Method Details
.for_non_existing_pacticipant(original_selector, type, ignore) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 29 def self.for_non_existing_pacticipant(original_selector, type, ignore) ResolvedSelector.new( pacticipant_id: NULL_PACTICIPANT_ID, pacticipant_name: original_selector[:pacticipant_name], type: type, ignore: ignore, original_selector: original_selector ) end |
.for_pacticipant(pacticipant, original_selector, type, ignore) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 19 def self.for_pacticipant(pacticipant, original_selector, type, ignore) ResolvedSelector.new( pacticipant_id: pacticipant.id, pacticipant_name: pacticipant.name, type: type, ignore: ignore, original_selector: original_selector ) end |
.for_pacticipant_and_non_existing_version(pacticipant, original_selector, type, ignore) ⇒ Object
rubocop: enable Metrics/ParameterLists
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 58 def self.for_pacticipant_and_non_existing_version(pacticipant, original_selector, type, ignore) ResolvedSelector.new( pacticipant_id: pacticipant.id, pacticipant_name: pacticipant.name, pacticipant_version_id: NULL_VERSION_ID, pacticipant_version_number: original_selector[:pacticipant_version_number], latest: original_selector[:latest], tag: original_selector[:tag], branch: original_selector[:branch], environment_name: original_selector[:environment_name], type: type, ignore: ignore, original_selector: original_selector ) end |
.for_pacticipant_and_version(pacticipant, version, original_selector, type, ignore, one_of_many = false) ⇒ Object
rubocop: disable Metrics/ParameterLists
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 40 def self.for_pacticipant_and_version(pacticipant, version, original_selector, type, ignore, one_of_many = false) ResolvedSelector.new( pacticipant_id: pacticipant.id, pacticipant_name: pacticipant.name, pacticipant_version_id: version.id, pacticipant_version_number: version.number, latest: original_selector[:latest], tag: original_selector[:tag], branch: original_selector[:branch], environment_name: original_selector[:environment_name], type: type, ignore: ignore, one_of_many: one_of_many, original_selector: original_selector ) end |
Instance Method Details
#branch ⇒ Object
102 103 104 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 102 def branch self[:branch] end |
#consider? ⇒ Boolean
173 174 175 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 173 def consider? !ignore? end |
#description ⇒ Object
rubocop: disable Metrics/CyclomaticComplexity
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 178 def description if latest_tagged? && pacticipant_version_number "the latest version of #{pacticipant_name} with tag #{tag} (#{pacticipant_version_number})" elsif latest_tagged? "the latest version of #{pacticipant_name} with tag #{tag} (no such version exists)" elsif latest_from_branch? && pacticipant_version_number "the latest version of #{pacticipant_name} from branch #{branch} (#{pacticipant_version_number})" elsif latest_from_branch? "the latest version of #{pacticipant_name} from branch #{branch} (no such version exists)" elsif latest? && pacticipant_version_number "the latest version of #{pacticipant_name} (#{pacticipant_version_number})" elsif latest? "the latest version of #{pacticipant_name} (no such version exists)" elsif tag && pacticipant_version_number "a version of #{pacticipant_name} with tag #{tag} (#{pacticipant_version_number})" elsif tag "a version of #{pacticipant_name} with tag #{tag} (no such version exists)" elsif environment_name && pacticipant_version_number prefix = one_of_many? ? "one of the versions" : "the version" "#{prefix} of #{pacticipant_name} currently deployed to #{environment_name} (#{pacticipant_version_number})" elsif environment_name "the version of #{pacticipant_name} currently deployed to #{environment_name} (no such version exists)" elsif pacticipant_version_number && version_does_not_exist? "version #{pacticipant_version_number} of #{pacticipant_name} (no such version exists)" elsif pacticipant_version_number "version #{pacticipant_version_number} of #{pacticipant_name}" elsif pacticipant_does_not_exist? "any version of #{pacticipant_name} (no such pacticipant exists)" else "any version of #{pacticipant_name}" end end |
#environment_name ⇒ Object
106 107 108 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 106 def environment_name self[:environment_name] end |
#ignore? ⇒ Boolean
169 170 171 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 169 def ignore? self[:ignore] end |
#inferred? ⇒ Boolean
Was this selector inferred based on the user’s query? (ie. the integrations were calculated because only one selector was specified)
161 162 163 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 161 def inferred? self[:type] == :inferred end |
#latest? ⇒ Boolean
94 95 96 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 94 def latest? self[:latest] end |
#latest_from_branch? ⇒ Boolean
126 127 128 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 126 def latest_from_branch? latest? && branch end |
#latest_tagged? ⇒ Boolean
122 123 124 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 122 def latest_tagged? latest? && tag end |
#latest_tagged_version_that_does_not_exist? ⇒ Boolean
142 143 144 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 142 def latest_tagged_version_that_does_not_exist? version_does_not_exist? && latest_tagged? end |
#most_specific_criterion ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 110 def most_specific_criterion if pacticipant_version_id { pacticipant_version_id: pacticipant_version_id } else { pacticipant_id: pacticipant_id } end end |
#one_of_many? ⇒ Boolean
165 166 167 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 165 def one_of_many? self[:one_of_many] end |
#only_pacticipant_name_specified? ⇒ Boolean
118 119 120 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 118 def only_pacticipant_name_specified? !!pacticipant_name && !branch && !tag && !latest? && !pacticipant_version_number end |
#pacticipant_does_not_exist? ⇒ Boolean
134 135 136 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 134 def pacticipant_does_not_exist? self[:pacticipant_id] == NULL_PACTICIPANT_ID end |
#pacticipant_id ⇒ Object
78 79 80 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 78 def pacticipant_id self[:pacticipant_id] end |
#pacticipant_name ⇒ Object
82 83 84 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 82 def pacticipant_name self[:pacticipant_name] end |
#pacticipant_or_version_does_not_exist? ⇒ Boolean
130 131 132 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 130 def pacticipant_or_version_does_not_exist? pacticipant_does_not_exist? || version_does_not_exist? end |
#pacticipant_version_id ⇒ Object
86 87 88 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 86 def pacticipant_version_id self[:pacticipant_version_id] end |
#pacticipant_version_number ⇒ Object
90 91 92 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 90 def pacticipant_version_number self[:pacticipant_version_number] end |
#pacticipant_version_specified_in_original_selector? ⇒ Boolean
74 75 76 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 74 def pacticipant_version_specified_in_original_selector? !!self.dig(:original_selector, :pacticipant_version_number) end |
#specified? ⇒ Boolean
Did the user specify this selector in the user’s query?
155 156 157 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 155 def specified? self[:type] == :specified end |
#specified_version_that_does_not_exist? ⇒ Boolean
146 147 148 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 146 def specified_version_that_does_not_exist? specified? && version_does_not_exist? end |
#tag ⇒ Object
98 99 100 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 98 def tag self[:tag] end |
#version_does_not_exist? ⇒ Boolean
138 139 140 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 138 def version_does_not_exist? !version_exists? end |
#version_exists? ⇒ Boolean
150 151 152 |
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 150 def version_exists? pacticipant_version_id != NULL_VERSION_ID end |