class PactBroker::Api::Resources::Pact
Public Instance Methods
allowed_methods()
click to toggle source
# File lib/pact_broker/api/resources/pact.rb, line 35 def allowed_methods ["GET", "PUT", "DELETE", "PATCH", "OPTIONS"] end
content_types_accepted()
click to toggle source
# File lib/pact_broker/api/resources/pact.rb, line 31 def content_types_accepted [["application/json", :from_json]] end
content_types_provided()
click to toggle source
# File lib/pact_broker/api/resources/pact.rb, line 22 def content_types_provided [ ["application/hal+json", :to_json], ["application/json", :to_json], ["text/html", :to_html], ["application/vnd.pactbrokerextended.v1+json", :to_extended_json] ] end
delete_resource()
click to toggle source
# File lib/pact_broker/api/resources/pact.rb, line 87 def delete_resource pact_service.delete(pact_params) set_post_deletion_response true end
from_json()
click to toggle source
# File lib/pact_broker/api/resources/pact.rb, line 57 def from_json response_code = pact ? 200 : 201 handle_webhook_events do if request.patch? && resource_exists? @pact = pact_service.merge_pact(pact_params) else @pact = pact_service.create_or_update_pact(pact_params) end end response.body = to_json response_code end
is_conflict?()
click to toggle source
# File lib/pact_broker/api/resources/pact.rb, line 39 def is_conflict? merge_conflict = request.patch? && resource_exists? && Pacts::Merger.conflict?(pact.json_content, pact_params.json_content) potential_duplicate_pacticipants?(pact_params.pacticipant_names) || merge_conflict || disallowed_modification? end
malformed_request?()
click to toggle source
# File lib/pact_broker/api/resources/pact.rb, line 45 def malformed_request? if request.patch? || request.put? invalid_json? || contract_validation_errors?(Contracts::PutPactParamsContract.new(pact_params), pact_params) else false end end
policy_name()
click to toggle source
# File lib/pact_broker/api/resources/pact.rb, line 93 def policy_name :'pacts::pact' end
policy_pacticipant()
click to toggle source
# File lib/pact_broker/api/resources/pact.rb, line 97 def policy_pacticipant if resource_exists? consumer else nil end end
resource_exists?()
click to toggle source
# File lib/pact_broker/api/resources/pact.rb, line 53 def resource_exists? !!pact end
to_extended_json()
click to toggle source
# File lib/pact_broker/api/resources/pact.rb, line 75 def to_extended_json decorator_class(:extended_pact_decorator).new(pact).to_json(decorator_options(metadata: identifier_from_path[:metadata])) end
to_html()
click to toggle source
# File lib/pact_broker/api/resources/pact.rb, line 79 def to_html PactBroker.configuration.html_pact_renderer.call( pact, { base_url: ui_base_url, badge_url: badge_url_for_latest_pact(pact, ui_base_url) }) end
to_json()
click to toggle source
# File lib/pact_broker/api/resources/pact.rb, line 71 def to_json decorator_class(:pact_decorator).new(pact).to_json(decorator_options(metadata: identifier_from_path[:metadata])) end
Private Instance Methods
disallowed_modification?()
click to toggle source
# File lib/pact_broker/api/resources/pact.rb, line 111 def disallowed_modification? if request.really_put? && pact_service.disallowed_modification?(pact, pact_params.json_content) message_params = { consumer_name: pact_params.consumer_name, consumer_version_number: pact_params.consumer_version_number, provider_name: pact_params.provider_name } set_json_error_message(message("errors.validation.pact_content_modification_not_allowed", message_params)) true else false end end
pact()
click to toggle source
# File lib/pact_broker/api/resources/pact.rb, line 107 def pact @pact ||= pact_service.find_pact(pact_params) end