Sha256: 2222ca6ce45afed67076df4490e0759ed9bf4e948a5e4b140969c0fea36db713

Contents?: true

Size: 1.14 KB

Versions: 1

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

1 entries across 1 versions & 1 rubygems

Version Path
mistral_client-1.3.0 lib/mistral_client/environment.rb