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



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

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

#before_saveObject

rubocop: disable Metrics/CyclomaticComplexity



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/pact_broker/domain/tag.rb', line 109

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)


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

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)


131
132
133
# File 'lib/pact_broker/domain/tag.rb', line 131

def latest_for_pacticipant?
  head_tag == self
end

#pacticipantObject



157
158
159
# File 'lib/pact_broker/domain/tag.rb', line 157

def pacticipant
  version.pacticipant
end