Sha256: 91cc99276ede50b4c3e60bcf2df71a50be3d816b9809bd1859dbdababf3d3660

Contents?: true

Size: 1.8 KB

Versions: 19

Compression:

Stored size: 1.8 KB

Contents

require "pact_broker/api/resources/base_resource"
require "pact_broker/api/resources/environment"

module PactBroker
  module Api
    module Resources
      class Environment < 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 resource_exists?
          !!environment
        end

        def malformed_request?
          if request.put? && environment
            invalid_json? || validation_errors_for_schema?(schema, params.merge(uuid: uuid))
          else
            false
          end
        end

        def from_json
          if environment
            @environment = replace_environment
            response.body = to_json
          else
            response.code = 404
          end
        end

        def policy_name
          :'deployments::environment'
        end

        def to_json
          decorator_class(:environment_decorator).new(environment).to_json(decorator_options)
        end

        def parsed_environment
          @parsed_environment ||= decorator_class(:environment_decorator).new(PactBroker::Deployments::Environment.new).from_json(request_body)
        end

        def environment
          @environment ||= environment_service.find(uuid)
        end

        def delete_resource
          environment_service.delete(uuid)
          true
        end

        def uuid
          identifier_from_path[:environment_uuid]
        end

        def replace_environment
          environment_service.replace(uuid, parsed_environment)
        end

        def schema
          api_contract_class(:environment_schema)
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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