Class: PactBroker::Matrix::ResolvedSelector

Inherits:
Hash
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ ResolvedSelector

Returns a new instance of ResolvedSelector.



14
15
16
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 14

def initialize(params = {})
  merge!(params)
end

Class Method Details

.for_pacticipant(pacticipant, type) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 18

def self.for_pacticipant(pacticipant, type)
  ResolvedSelector.new(
    pacticipant_id: pacticipant.id,
    pacticipant_name: pacticipant.name,
    type: type
  )
end

.for_pacticipant_and_non_existing_version(pacticipant, original_selector, type) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 40

def self.for_pacticipant_and_non_existing_version(pacticipant, original_selector, type)
  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],
    type: type
  )
end

.for_pacticipant_and_version(pacticipant, version, pact_publication_ids = [], verification_ids = [], original_selector, type) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 26

def self.for_pacticipant_and_version(pacticipant, version, pact_publication_ids = [], verification_ids = [], original_selector, type)
  ResolvedSelector.new(
    pacticipant_id: pacticipant.id,
    pacticipant_name: pacticipant.name,
    pacticipant_version_id: version.id,
    pact_publication_ids: pact_publication_ids,
    verification_ids: verification_ids,
    pacticipant_version_number: version.number,
    latest: original_selector[:latest],
    tag: original_selector[:tag],
    type: type
  )
end

Instance Method Details

#descriptionObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 107

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? && 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 pacticipant_version_number
    "version #{pacticipant_version_number} of #{pacticipant_name}"
  else
    "any version of #{pacticipant_name}"
  end
end

#inferred?Boolean

Was this selector inferred based on the user’s query? (ie. the integrations were calculated because only one selector was specified)

Returns:

  • (Boolean)


103
104
105
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 103

def inferred?
  self[:type] == :inferred
end

#latest?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 68

def latest?
  self[:latest]
end

#latest_tagged?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 76

def latest_tagged?
  latest? && tag
end

#latest_tagged_version_that_does_not_exist?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 84

def latest_tagged_version_that_does_not_exist?
  version_does_not_exist? && latest_tagged?
end

#pacticipant_idObject



52
53
54
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 52

def pacticipant_id
  self[:pacticipant_id]
end

#pacticipant_nameObject



56
57
58
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 56

def pacticipant_name
  self[:pacticipant_name]
end

#pacticipant_version_idObject



60
61
62
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 60

def pacticipant_version_id
  self[:pacticipant_version_id]
end

#pacticipant_version_numberObject



64
65
66
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 64

def pacticipant_version_number
  self[:pacticipant_version_number]
end

#specified?Boolean

Did the user specify this selector in the user’s query?

Returns:

  • (Boolean)


97
98
99
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 97

def specified?
  self[:type] == :specified
end

#specified_version_that_does_not_exist?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 88

def specified_version_that_does_not_exist?
  specified? && version_does_not_exist?
end

#tagObject



72
73
74
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 72

def tag
  self[:tag]
end

#version_does_not_exist?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 80

def version_does_not_exist?
  !version_exists?
end

#version_exists?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 92

def version_exists?
  pacticipant_version_id != NULL_VERSION_ID
end