Sha256: dca59763da7ffa108a80cd50fe7c082c0c4046bf895e39f574a0e9e3a39b7078

Contents?: true

Size: 1.46 KB

Versions: 8

Compression:

Stored size: 1.46 KB

Contents

require "pact_broker/api/resources/base_resource"
require "pact_broker/api/decorators/branch_version_decorator"

module PactBroker
  module Api
    module Resources
      class BranchVersion < BaseResource
        def content_types_provided
          [["application/hal+json", :to_json]]
        end

        def content_types_accepted
          [["application/json", :from_json]]
        end

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

        def put_can_create?
          true
        end

        def resource_exists?
          !!branch_version
        end

        def to_json
          decorator_class(:branch_version_decorator).new(branch_version).to_json(**decorator_options)
        end

        def delete_resource
          branch_service.delete_branch_version(branch_version)
          true
        end

        def from_json
          already_existed = !!branch_version
          @branch_version = branch_service.find_or_create_branch_version(**identifier_from_path)
          # Make it return a 201 by setting the Location header
          response.headers["Location"] = branch_version_url(branch_version, base_url) unless already_existed
          response.body = to_json
        end

        def policy_name
          :'versions::branch_version'
        end

        private

        def branch_version
          @branch_version ||= branch_service.find_branch_version(**identifier_from_path)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pact_broker-2.112.0 lib/pact_broker/api/resources/branch_version.rb
pact_broker-2.111.0 lib/pact_broker/api/resources/branch_version.rb
pact_broker-2.109.1 lib/pact_broker/api/resources/branch_version.rb
pact_broker-2.109.0 lib/pact_broker/api/resources/branch_version.rb
pact_broker-2.108.0 lib/pact_broker/api/resources/branch_version.rb
pact_broker-2.107.1 lib/pact_broker/api/resources/branch_version.rb
pact_broker-2.107.0 lib/pact_broker/api/resources/branch_version.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/api/resources/branch_version.rb