Class: OsVm::ShellCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/osvm/shell_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine, shells) ⇒ ShellCollection

Returns a new instance of ShellCollection.



5
6
7
8
# File 'lib/osvm/shell_collection.rb', line 5

def initialize(machine, shells)
  @machine = machine
  @shells = shells.transform_keys(&:to_s).freeze
end

Instance Attribute Details

#machineObject (readonly, protected)

Returns the value of attribute machine.



46
47
48
# File 'lib/osvm/shell_collection.rb', line 46

def machine
  @machine
end

#shellsObject (readonly, protected)

Returns the value of attribute shells.



46
47
48
# File 'lib/osvm/shell_collection.rb', line 46

def shells
  @shells
end

Instance Method Details

#[](name) ⇒ Object



10
11
12
# File 'lib/osvm/shell_collection.rb', line 10

def [](name)
  fetch(name)
end

#eachObject



36
37
38
# File 'lib/osvm/shell_collection.rb', line 36

def each(&)
  shells.each(&)
end

#fetch(name, *default) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
# File 'lib/osvm/shell_collection.rb', line 14

def fetch(name, *default)
  raise ArgumentError, 'wrong number of arguments' if default.length > 1

  key = name.to_s
  return shells.fetch(key) if shells.has_key?(key)
  return yield(name) if block_given?
  return default.first if default.length == 1

  raise KeyError, "unknown shell #{name.inspect} for machine #{machine.name}"
end

#key?(name) ⇒ Boolean Also known as: include?, member?

Returns:

  • (Boolean)


25
26
27
# File 'lib/osvm/shell_collection.rb', line 25

def key?(name)
  shells.has_key?(name.to_s)
end

#keysObject



32
33
34
# File 'lib/osvm/shell_collection.rb', line 32

def keys
  shells.keys
end

#to_hObject



40
41
42
# File 'lib/osvm/shell_collection.rb', line 40

def to_h
  shells.dup
end