Class: PactBroker::Api::Resources::CanIDeployBadge

Inherits:
BaseResource
  • Object
show all
Defined in:
lib/pact_broker/api/resources/can_i_deploy_badge.rb

Instance Method Summary collapse

Constructor Details

#initializeCanIDeployBadge

Returns a new instance of CanIDeployBadge.



8
9
10
11
12
13
14
15
16
17
# 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

Instance Method Details

#allowed_methodsObject



19
20
21
# File 'lib/pact_broker/api/resources/can_i_deploy_badge.rb', line 19

def allowed_methods
  ["GET", "OPTIONS"]
end

#content_types_providedObject



23
24
25
# File 'lib/pact_broker/api/resources/can_i_deploy_badge.rb', line 23

def content_types_provided
  [["image/svg+xml", :to_svg]]
end

#forbidden?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/pact_broker/api/resources/can_i_deploy_badge.rb', line 40

def forbidden?
  false
end

#is_authorized?(authorization_header) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# 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?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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_nameObject



62
63
64
# File 'lib/pact_broker/api/resources/can_i_deploy_badge.rb', line 62

def policy_name
  :'badges::badge'
end

#previously_existed?Boolean

Only called if resource_exists? returns false

Returns:

  • (Boolean)


32
33
34
# File 'lib/pact_broker/api/resources/can_i_deploy_badge.rb', line 32

def previously_existed?
  true
end

#resource_exists?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/pact_broker/api/resources/can_i_deploy_badge.rb', line 27

def resource_exists?
  false
end