Sha256: 815ddb419a90a219e731a810ce7580e47b1da9821c571f782422bb04d9faa930

Contents?: true

Size: 1.14 KB

Versions: 4

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)
      @server = server
      @definition = parse_definition(definition) if definition
      @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)
      if definition['variables'].is_a? Hash
        definition['variables'] = definition['variables'].to_json
      end
      definition
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mistral_client-1.2.1 lib/mistral_client/environment.rb
mistral_client-1.2.0 lib/mistral_client/environment.rb
mistral_client-1.1.0 lib/mistral_client/environment.rb
mistral_client-1.0.0 lib/mistral_client/environment.rb