Sha256: d97f8b1a0942c69eb8cd7b85c532d506b12e9af3ccc784d9f473429b6c53027a

Contents?: true

Size: 860 Bytes

Versions: 9

Compression:

Stored size: 860 Bytes

Contents

class DockerHelpers
  def initialize(compose_path)
    @compose_path = compose_path
    @compose = YAML.load(File.read(compose_path))
  end

  def add_link(target_service, linked_service)
    service = @compose[target_service]
    unless service['links'].is_a? Array
      service['links'] = []
    end
    service['links'].push(linked_service)
    save
  end

  def add_env(target_service, variable_key, variable_value)
    service = @compose[target_service]
    unless service['environment'].is_a? Hash
      service['environment'] = {}
    end
    service['environment'][variable_key] = variable_value
    save
  end

  def add_service(name, definition)
    service = {}
    service[name] = YAML.load(definition)
    @compose.merge!(service)
    save
  end

  private

  def save
    File.open(@compose_path, 'w') { |f| f.write @compose.to_yaml }
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
potassium-5.1.4 lib/potassium/helpers/docker-helpers.rb
potassium-5.1.3 lib/potassium/helpers/docker-helpers.rb
potassium-5.1.2 lib/potassium/helpers/docker-helpers.rb
potassium-5.1.1 lib/potassium/helpers/docker-helpers.rb
potassium-3.0.0 lib/potassium/helpers/docker-helpers.rb
potassium-2.3.0 lib/potassium/helpers/docker-helpers.rb
potassium-2.2.0 lib/potassium/helpers/docker-helpers.rb
potassium-2.1.0 lib/potassium/helpers/docker-helpers.rb
potassium-2.0.0 lib/potassium/helpers/docker-helpers.rb