Class: PactBroker::Domain::Tag

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/pact_broker/domain/tag.rb

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object



176
177
178
# File 'lib/pact_broker/domain/tag.rb', line 176

def <=> other
  name <=> other.name
end

#before_saveObject

rubocop: disable Metrics/CyclomaticComplexity



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/pact_broker/domain/tag.rb', line 132

def before_save
  super
  if version
    if version.order && self.version_order.nil?
      self.version_order = version.order
    end

    if self.pacticipant_id.nil?
      if version.pacticipant_id
        self.pacticipant_id = version.pacticipant_id
      elsif version&.pacticipant&.id
        self.pacticipant_id = version.pacticipant.id
      end
    end
  end

  if version_order.nil? || pacticipant_id.nil?
    raise PactBroker::Error.new("Need to set version_order and pacticipant_id for tags now")
  end
end

#latest_for_pact_publication?(pact_publication) ⇒ Boolean

Returns:

  • (Boolean)


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/pact_broker/domain/tag.rb', line 160

def latest_for_pact_publication?(pact_publication)
  tag_pp_join = {
    Sequel[:pact_publications][:consumer_version_id] => Sequel[:tags][:version_id],
    Sequel[:pact_publications][:consumer_id] => pact_publication.consumer_id,
    Sequel[:pact_publications][:provider_id] => pact_publication.provider_id,
    Sequel[:tags][:name] => name
  }
  own_version_order = self.version_order
  Tag.join(:pact_publications, tag_pp_join) do
    Sequel[:tags][:version_order] > own_version_order
  end
  .where(pacticipant_id: pact_publication.consumer_id)
  .limit(1)
  .empty?
end

#latest_for_pacticipant?Boolean Also known as: latest?

rubocop: enable Metrics/CyclomaticComplexity

Returns:

  • (Boolean)


154
155
156
# File 'lib/pact_broker/domain/tag.rb', line 154

def latest_for_pacticipant?
  head_tag == self
end

#pacticipantObject



180
181
182
# File 'lib/pact_broker/domain/tag.rb', line 180

def pacticipant
  version.pacticipant
end