Sha256: 81faf7308df0ca72964722f1deca52446d1aed8f2d73083617254748ae966f66

Contents?: true

Size: 1.45 KB

Versions: 8

Compression:

Stored size: 1.45 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.106.0 lib/pact_broker/api/resources/branch_version.rb
pact_broker-2.105.0 lib/pact_broker/api/resources/branch_version.rb
pact_broker-2.104.0 lib/pact_broker/api/resources/branch_version.rb
pact_broker-2.103.0 lib/pact_broker/api/resources/branch_version.rb
pact_broker-2.102.2 lib/pact_broker/api/resources/branch_version.rb
pact_broker-2.102.1 lib/pact_broker/api/resources/branch_version.rb
pact_broker-2.102.0 lib/pact_broker/api/resources/branch_version.rb
pact_broker-2.101.0 lib/pact_broker/api/resources/branch_version.rb