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



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

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, original_selector, type) ⇒ Object



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

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

Instance Method Details

#descriptionObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 117

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)


113
114
115
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 113

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

#latest?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 66

def latest?
  self[:latest]
end

#latest_tagged?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 86

def latest_tagged?
  latest? && tag
end

#latest_tagged_version_that_does_not_exist?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 94

def latest_tagged_version_that_does_not_exist?
  version_does_not_exist? && latest_tagged?
end

#most_specific_criterionObject



74
75
76
77
78
79
80
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 74

def most_specific_criterion
  if pacticipant_version_id
    { pacticipant_version_id: pacticipant_version_id }
  else
    { pacticipant_id: pacticipant_id }
  end
end

#only_pacticipant_name_specified?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 82

def only_pacticipant_name_specified?
  pacticipant_name && !tag && !latest? && !pacticipant_version_number
end

#pacticipant_idObject



50
51
52
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 50

def pacticipant_id
  self[:pacticipant_id]
end

#pacticipant_nameObject



54
55
56
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 54

def pacticipant_name
  self[:pacticipant_name]
end

#pacticipant_version_idObject



58
59
60
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 58

def pacticipant_version_id
  self[:pacticipant_version_id]
end

#pacticipant_version_numberObject



62
63
64
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 62

def pacticipant_version_number
  self[:pacticipant_version_number]
end

#specified?Boolean

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

Returns:

  • (Boolean)


107
108
109
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 107

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

#specified_version_that_does_not_exist?Boolean

Returns:

  • (Boolean)


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

def specified_version_that_does_not_exist?
  specified? && version_does_not_exist?
end

#tagObject



70
71
72
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 70

def tag
  self[:tag]
end

#version_does_not_exist?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/pact_broker/matrix/resolved_selector.rb', line 90

def version_does_not_exist?
  !version_exists?
end

#version_exists?Boolean

Returns:

  • (Boolean)


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

def version_exists?
  pacticipant_version_id != NULL_VERSION_ID
end