class PactBroker::Domain::Version
Public Instance Methods
after_create()
click to toggle source
Isn't called on upsert when the record is updated with Sqlite Is called with Postgres/MySQL Haven't had time to dig into why
Calls superclass method
# File lib/pact_broker/domain/version.rb, line 265 def after_create super OrderVersions.(self) unless self.order refresh end
before_destroy()
click to toggle source
Calls superclass method
# File lib/pact_broker/domain/version.rb, line 271 def before_destroy PactBroker::Deployments::DeployedVersion.where(version: self).destroy PactBroker::Deployments::ReleasedVersion.where(version: self).destroy PactBroker::Domain::Tag.where(version: self).destroy super end
branch_names()
click to toggle source
# File lib/pact_broker/domain/version.rb, line 311 def branch_names branch_versions.collect(&:branch_name) end
branch_version_for_branch(branch)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 303 def branch_version_for_branch(branch) branch_versions.find { | branch_version | branch_version.branch_id == branch.id } end
branch_version_for_branch_name(branch_name)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 307 def branch_version_for_branch_name(branch_name) branch_versions.find { | branch_version | branch_version.branch_name == branch_name } end
calculate_max_version_order_and_join_back_to_versions(query, selector)
click to toggle source
private
# File lib/pact_broker/domain/version.rb, line 246 def calculate_max_version_order_and_join_back_to_versions(query, selector) versions_join = { Sequel[:versions][:pacticipant_id] => Sequel[:latest][:pacticipant_id], Sequel[:versions][:order] => Sequel[:latest][:latest_version_order] } group_by_cols = selector.tag == true ? [Sequel[:versions][:pacticipant_id], Sequel[:tags][:name]] : [Sequel[:versions][:pacticipant_id]] max_order_for_each_pacticipant = query .select_group(*group_by_cols) .select_append{ max(order).as(latest_version_order) } join(max_order_for_each_pacticipant, versions_join, table_alias: :latest) end
currently_deployed()
click to toggle source
# File lib/pact_broker/domain/version.rb, line 116 def currently_deployed deployed_version_query = PactBroker::Deployments::DeployedVersion.currently_deployed where(id: deployed_version_query.select(:version_id)) end
currently_deployed_to_environment(environment_name, pacticipant_name)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 104 def currently_deployed_to_environment(environment_name, pacticipant_name) deployed_version_query = PactBroker::Deployments::DeployedVersion.currently_deployed.for_environment_name(environment_name) deployed_version_query = deployed_version_query.for_pacticipant_name(pacticipant_name) if pacticipant_name where(id: deployed_version_query.select(:version_id)) end
currently_in_environment(environment_name, pacticipant_name)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 100 def currently_in_environment(environment_name, pacticipant_name) currently_deployed_to_environment(environment_name, pacticipant_name).union(currently_supported_in_environment(environment_name, pacticipant_name)) end
currently_supported()
click to toggle source
# File lib/pact_broker/domain/version.rb, line 121 def currently_supported supported_version_query = PactBroker::Deployments::ReleasedVersion.currently_supported where(id: supported_version_query.select(:version_id)) end
currently_supported_in_environment(environment_name, pacticipant_name)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 110 def currently_supported_in_environment(environment_name, pacticipant_name) supported_version_query = PactBroker::Deployments::ReleasedVersion.currently_supported.for_environment_name(environment_name) supported_version_query = supported_version_query.for_pacticipant_name(pacticipant_name) if pacticipant_name where(id: supported_version_query.select(:version_id)) end
delete()
click to toggle source
Calls superclass method
# File lib/pact_broker/domain/version.rb, line 190 def delete require "pact_broker/pacts/pact_publication" require "pact_broker/domain/verification" require "pact_broker/domain/tag" require "pact_broker/deployments/deployed_version" require "pact_broker/deployments/released_version" PactBroker::Deployments::DeployedVersion.where(version: self).delete PactBroker::Deployments::ReleasedVersion.where(version: self).delete PactBroker::Domain::Verification.where(provider_version: self).delete PactBroker::Pacts::PactPublication.where(consumer_version: self).delete PactBroker::Domain::Tag.where(version: self).delete super end
first_for_pacticipant_id_and_branch(pacticipant_id, branch)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 75 def first_for_pacticipant_id_and_branch(pacticipant_id, branch) first_version_id = PactBroker::Versions::BranchVersion .select(:version_id) .where(pacticipant_id: pacticipant_id, branch_name: branch) .order(:created_at) .limit(1) where(id: first_version_id).single_record end
for(pacticipant_name, version_number)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 67 def for(pacticipant_name, version_number) where_pacticipant_name(pacticipant_name).where_number(version_number).single_record end
for_main_branches()
click to toggle source
# File lib/pact_broker/domain/version.rb, line 160 def for_main_branches matching_branch_version_ids = PactBroker::Versions::BranchVersion .select(:version_id) .join(:pacticipants, { Sequel[:branch_versions][:pacticipant_id] => Sequel[:pacticipants][:id] }) .join(:branches, { Sequel[:branches][:id] => Sequel[:branch_versions][:branch_id], Sequel[:branches][:name] => Sequel[:pacticipants][:main_branch] }) where(id: matching_branch_version_ids) end
for_selector(selector)
click to toggle source
rubocop: disable Metrics/CyclomaticComplexity
# File lib/pact_broker/domain/version.rb, line 206 def for_selector(selector) query = self query = query.where_pacticipant_name(selector.pacticipant_name) if selector.pacticipant_name query = query.currently_in_environment(selector.environment_name, selector.pacticipant_name) if selector.environment_name query = query.currently_deployed if selector.respond_to?(:currently_deployed?) && selector.currently_deployed? query = query.currently_supported if selector.respond_to?(:currently_supported?) && selector.currently_supported? query = query.where_tag(selector.tag) if selector.tag query = query.where_number(selector.pacticipant_version_number) if selector.respond_to?(:pacticipant_version_number) && selector.pacticipant_version_number query = query.where_age_less_than(selector.max_age) if selector.respond_to?(:max_age) && selector.max_age latest_applied = false if selector.respond_to?(:main_branch) && selector.main_branch if selector.latest latest_applied = true query = query.latest_for_main_branches else query = query.for_main_branches end end if selector.branch if selector.latest latest_applied = true query = query.where_branch_head_name(selector.branch) else query = query.where_branch_name(selector.branch) end end if selector.latest && !latest_applied calculate_max_version_order_and_join_back_to_versions(query, selector) else query end end
latest_for_branch?()
click to toggle source
# File lib/pact_broker/domain/version.rb, line 295 def latest_for_branch? branch_heads.any? end
latest_for_main_branches()
click to toggle source
# File lib/pact_broker/domain/version.rb, line 169 def latest_for_main_branches pacticipants_join = { Sequel[:branch_heads][:pacticipant_id] => Sequel[:pacticipants][:id], Sequel[:branch_heads][:branch_name] => Sequel[:pacticipants][:main_branch] } matching_branch_version_ids = PactBroker::Versions::BranchHead .select(:version_id) .join(:pacticipants, pacticipants_join) where(id: matching_branch_version_ids) end
latest_for_pacticipant?()
click to toggle source
# File lib/pact_broker/domain/version.rb, line 299 def latest_for_pacticipant? latest_version_for_pacticipant == self end
latest_pact_publication()
click to toggle source
What about provider??? This makes no sense
# File lib/pact_broker/domain/version.rb, line 291 def latest_pact_publication pact_publications.last end
latest_version_for_pacticipant(pacticipant)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 61 def latest_version_for_pacticipant(pacticipant) where(pacticipant: pacticipant) .order(Sequel.desc(:order)) .limit(1) end
latest_versions_for_pacticipant_branches(pacticipant_id, branch_names)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 84 def latest_versions_for_pacticipant_branches(pacticipant_id, branch_names) where(id: PactBroker::Versions::BranchHead.where(pacticipant_id: pacticipant_id, branch_name: branch_names).select(:version_id)) end
tag_names()
click to toggle source
# File lib/pact_broker/domain/version.rb, line 315 def tag_names tags.collect(&:name) end
to_s()
click to toggle source
# File lib/pact_broker/domain/version.rb, line 278 def to_s "Version: number=#{number}, pacticipant=#{pacticipant_id}" end
version_and_updated_date()
click to toggle source
# File lib/pact_broker/domain/version.rb, line 282 def version_and_updated_date "Version #{number} - #{updated_at.to_time.localtime.strftime("%d/%m/%Y")}" end
where_age_less_than(days)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 185 def where_age_less_than(days) start_date = Date.today - days where{ versions[:created_at] >= start_date } end
where_branch_head_name(branch_name)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 151 def where_branch_head_name(branch_name) if branch_name == true where(id: PactBroker::Versions::BranchHead.select(:version_id)) else where(id: PactBroker::Versions::BranchHead.select(:version_id).where(branch_name: branch_name)) end end
where_branch_name(branch_name)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 139 def where_branch_name(branch_name) if branch_name == true where(id: PactBroker::Versions::BranchVersion.select(:version_id)) else matching_branch_ids = PactBroker::Versions::Branch.select(:id).where(name: branch_name) matching_branch_version_ids = PactBroker::Versions::BranchVersion .select(:version_id) .where(branch_id: matching_branch_ids) where(id: matching_branch_version_ids) end end
where_number(number)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 181 def where_number(number) where(name_like(:number, number)) end
where_pacticipant_name(pacticipant_name)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 88 def where_pacticipant_name(pacticipant_name) where(Sequel[:versions][:pacticipant_id] => db[:pacticipants].select(:id).where(name_like(:name, pacticipant_name))) # If we do a join, we get the extra columns from the pacticipant table that then # make == not work # join(:pacticipants) do | p | # Sequel.&( # { Sequel[first_source_alias][:pacticipant_id] => Sequel[p][:id] }, # name_like(Sequel[p][:name], pacticipant_name) # ) # end end
where_pacticipant_name_and_version_number(pacticipant_name, version_number)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 71 def where_pacticipant_name_and_version_number(pacticipant_name, version_number) where_pacticipant_name(pacticipant_name).where_number(version_number) end
where_tag(tag)
click to toggle source
# File lib/pact_broker/domain/version.rb, line 126 def where_tag(tag) if tag == true join(:tags, Sequel[:tags][:version_id] => Sequel[first_source_alias][:id]) else join(:tags) do | tags | Sequel.&( { Sequel[first_source_alias][:id] => Sequel[tags][:version_id] }, name_like(Sequel[tags][:name], tag) ) end end end
with_branch()
click to toggle source
# File lib/pact_broker/domain/version.rb, line 53 def with_branch where(id: PactBroker::Versions::BranchVersion.select(:version_id)) end
with_user_created_branch()
click to toggle source
# File lib/pact_broker/domain/version.rb, line 57 def with_user_created_branch where(id: PactBroker::Versions::BranchVersion.select(:version_id).where(auto_created: false)) end