Sha256: bb75f8235f99f0362e55fd7ba010eff69b01585f643151dce511fd7ede551248

Contents?: true

Size: 1.21 KB

Versions: 28

Compression:

Stored size: 1.21 KB

Contents

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

module PactBroker
  module Api
    module Resources
      class Label < 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 from_json
          unless label
            @label = label_service.create(identifier_from_path)
            # Make it return a 201 by setting the Location header
            response.headers["Location"] = label_url(label, base_url)
          end
          response.body = to_json
        end

        def resource_exists?
          !!label
        end

        def policy_name
          :'labels::label'
        end

        def to_json
          decorator_class(:label_decorator).new(label).to_json(decorator_options)
        end

        def label
          @label ||= label_service.find(identifier_from_path)
        end

        def delete_resource
          label_service.delete(identifier_from_path)
          true
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
pact_broker-2.100.0 lib/pact_broker/api/resources/label.rb
pact_broker-2.99.0 lib/pact_broker/api/resources/label.rb
pact_broker-2.98.0 lib/pact_broker/api/resources/label.rb
pact_broker-2.97.0 lib/pact_broker/api/resources/label.rb
pact_broker-2.96.0 lib/pact_broker/api/resources/label.rb
pact_broker-2.95.1 lib/pact_broker/api/resources/label.rb
pact_broker-2.95.0 lib/pact_broker/api/resources/label.rb
pact_broker-2.94.0 lib/pact_broker/api/resources/label.rb
pact_broker-2.93.4 lib/pact_broker/api/resources/label.rb
pact_broker-2.93.3 lib/pact_broker/api/resources/label.rb
pact_broker-2.93.2 lib/pact_broker/api/resources/label.rb
pact_broker-2.93.1 lib/pact_broker/api/resources/label.rb
pact_broker-2.93.0 lib/pact_broker/api/resources/label.rb
pact_broker-2.92.0 lib/pact_broker/api/resources/label.rb
pact_broker-2.91.0 lib/pact_broker/api/resources/label.rb
pact_broker-2.90.0 lib/pact_broker/api/resources/label.rb
pact_broker-2.89.1 lib/pact_broker/api/resources/label.rb
pact_broker-2.89.0 lib/pact_broker/api/resources/label.rb
pact_broker-2.88.0 lib/pact_broker/api/resources/label.rb
pact_broker-2.87.0 lib/pact_broker/api/resources/label.rb