Sha256: 533e6e09963ef67a6d4ee20234c00db3a19c6d3b399c787874543f3b53231ee7

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

module MistralClient
  class Environment < Base
    UNICODE_FIELDS = %w[name scope description].freeze
    JSON_FIELDS = %w[variables].freeze
    BOOL_FIELDS = [].freeze
    PATH = 'environments'.freeze
    include MistralClient::Mixins::MistralObject
    include MistralClient::Mixins::Definable

    def initialize(server, definition = nil, name: nil)
      super()
      @server = server
      @definition = definition ? parse_definition(definition) : nil
      @name = name
      if @name
        reload
      elsif @definition
        create_environment
      end
    end

    def reload
      super(@name)
    end

    def delete!
      resp = @server.delete("#{PATH}/#{@name}")
      return true if resp.code == 204

      raise MistralClient::MistralError,
            "Could not perform the requested operation:\n#{resp.body}"
    end

    private

    def create_environment
      resp = @server.post(PATH, @definition.to_json, json: true)
      ivars_from_response(resp)
    end

    def massage_definition(definition)
      definition['variables'] = definition['variables'].to_json if definition['variables'].is_a? Hash
      definition
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mistral_client-3.0.0 lib/mistral_client/environment.rb
mistral_client-2.0.0 lib/mistral_client/environment.rb