Class: Kuby::Docker::PackageList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/kuby/docker/package_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package_tuples) ⇒ PackageList

T::Sig::WithoutRuntime.sig { params(package_tuples: T::Array[[Symbol, T.nilable(String)]]).void }



17
18
19
20
# File 'lib/kuby/docker/package_list.rb', line 17

def initialize(package_tuples)
  @packages = []
  package_tuples.each { |name, version| add(name, version) }
end

Instance Attribute Details

#packagesObject (readonly)

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



14
15
16
# File 'lib/kuby/docker/package_list.rb', line 14

def packages
  @packages
end

Instance Method Details

#[](name) ⇒ Object

T::Sig::WithoutRuntime.sig { params(name: Symbol).returns(T.nilable(Distro::PackageImpl)) }



23
24
25
# File 'lib/kuby/docker/package_list.rb', line 23

def [](name)
  packages.find { |pkg| pkg.name == name }
end

#add(name, version = nil) ⇒ Object

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



28
29
30
# File 'lib/kuby/docker/package_list.rb', line 28

def add(name, version = nil)
  packages << Packages::Package.new(name, version)
end

#delete(name) ⇒ Object

T::Sig::WithoutRuntime.sig { params(name: String).void }



33
34
35
# File 'lib/kuby/docker/package_list.rb', line 33

def delete(name)
  packages.delete_if { |pkg| pkg.name == name }
end

#each(&block) ⇒ Object

T::Sig::WithoutRuntime.sig

override.params(
  block: T.proc.params(package: Distro::PackageImpl).void
)
.void



43
44
45
# File 'lib/kuby/docker/package_list.rb', line 43

def each(&block)
  packages.each(&block)
end

#empty?Boolean

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

Returns:

  • (Boolean)


48
49
50
# File 'lib/kuby/docker/package_list.rb', line 48

def empty?
  packages.empty?
end