Class: Kuby::Docker::PackagePhase

Inherits:
Layer
  • Object
show all
Defined in:
lib/kuby/docker/package_phase.rb

Instance Attribute Summary collapse

Attributes inherited from Layer

#environment

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ PackagePhase

T::Sig::WithoutRuntime.sig { params(environment: Kuby::Environment).void }



14
15
16
17
18
# File 'lib/kuby/docker/package_phase.rb', line 14

def initialize(environment)
  super

  @operations = []
end

Instance Attribute Details

#operationsObject (readonly)

T::Sig::WithoutRuntime.sig { returns(T::Array) }



11
12
13
# File 'lib/kuby/docker/package_phase.rb', line 11

def operations
  @operations
end

Instance Method Details

#add(package_name, version = nil) ⇒ Object

T::Sig::WithoutRuntime.sig { params(package_name: Symbol, version: T.nilable(String)).void }



21
22
23
# File 'lib/kuby/docker/package_phase.rb', line 21

def add(package_name, version = nil)
  operations << [:add, package_name, version]
end

#apply_to(dockerfile) ⇒ Object

T::Sig::WithoutRuntime.sig { override.params(dockerfile: Kuby::Docker::Dockerfile).void }



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kuby/docker/package_phase.rb', line 31

def apply_to(dockerfile)
  packages = distro_spec.default_packages.dup

  operations.each do |operator, package_name, version|
    if operator == :add
      packages << [package_name, version]
    else
      packages.reject! do |pkg_name_to_del, *|
        pkg_name_to_del == package_name
      end
    end
  end

  package_impls = packages.map do |package_name, version|
    get_package(package_name, version)
  end

  distro_spec.install(package_impls, into: dockerfile)
end

#remove(package_name) ⇒ Object

T::Sig::WithoutRuntime.sig { params(package_name: Symbol).void }



26
27
28
# File 'lib/kuby/docker/package_phase.rb', line 26

def remove(package_name)
  operations << [:remove, package_name, nil]
end