class PactBroker::Api::Resources::CanIDeployBadge

Attributes

options[R]
selectors[R]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/pact_broker/api/resources/can_i_deploy_badge.rb, line 8
def initialize
  super
  selector = PactBroker::Matrix::UnresolvedSelector.new(pacticipant_name: pacticipant_name, latest: true, tag: identifier_from_path[:tag])
  @options = {
    latestby: "cvp",
    latest: true,
    tag: identifier_from_path[:to]
  }
  @selectors = [selector]
end

Public Instance Methods

allowed_methods() click to toggle source
# File lib/pact_broker/api/resources/can_i_deploy_badge.rb, line 19
def allowed_methods
  ["GET", "OPTIONS"]
end
content_types_provided() click to toggle source
# File lib/pact_broker/api/resources/can_i_deploy_badge.rb, line 23
def content_types_provided
  [["image/svg+xml", :to_svg]]
end
forbidden?() click to toggle source
# File lib/pact_broker/api/resources/can_i_deploy_badge.rb, line 40
def forbidden?
  false
end
is_authorized?(authorization_header) click to toggle source
Calls superclass method
# File lib/pact_broker/api/resources/can_i_deploy_badge.rb, line 36
def is_authorized?(authorization_header)
  super || PactBroker.configuration.enable_public_badge_access
end
moved_temporarily?() click to toggle source
# File lib/pact_broker/api/resources/can_i_deploy_badge.rb, line 44
def moved_temporarily?
  response.headers["Cache-Control"] = "no-cache"
  begin
    if pacticipant
      if version
        badge_service.can_i_deploy_badge_url(identifier_from_path[:tag], identifier_from_path[:to], label, results.deployable?)
      else
        badge_service.error_badge_url("version", "not found")
      end
    else
      badge_service.error_badge_url(selectors.first.pacticipant_name, "not found")
    end
  rescue StandardError => e
    # Want to render a badge, even if there's an error
    badge_service.error_badge_url("error", ErrorResponseBodyGenerator.display_message(e, "reference: #{PactBroker::Errors.generate_error_reference}"))
  end
end
policy_name() click to toggle source
# File lib/pact_broker/api/resources/can_i_deploy_badge.rb, line 62
def policy_name
  :'badges::badge'
end
previously_existed?() click to toggle source

Only called if resource_exists? returns false

# File lib/pact_broker/api/resources/can_i_deploy_badge.rb, line 32
def previously_existed?
  true
end
resource_exists?() click to toggle source
# File lib/pact_broker/api/resources/can_i_deploy_badge.rb, line 27
def resource_exists?
  false
end

Private Instance Methods

label() click to toggle source
# File lib/pact_broker/api/resources/can_i_deploy_badge.rb, line 78
def label
  lab = request.query["label"]
  lab && !lab.empty? ? lab : nil
end
results() click to toggle source
# File lib/pact_broker/api/resources/can_i_deploy_badge.rb, line 70
def results
  @results ||= matrix_service.can_i_deploy(selectors, options)
end
version() click to toggle source
# File lib/pact_broker/api/resources/can_i_deploy_badge.rb, line 74
def version
  @version ||= version_service.find_by_pacticipant_name_and_latest_tag(identifier_from_path[:pacticipant_name], identifier_from_path[:tag])
end