Class: VagrantPlugins::Utm::Model::ListResult

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant_utm/model/list_result.rb

Overview

Represents the result of a ‘utmctl list’ operation.

Defined Under Namespace

Classes: ListResultItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ListResult

Initialize the result from raw data.

Parameters:

  • data (Array<Hash>)

    The raw data.



13
14
15
16
17
18
19
# File 'lib/vagrant_utm/model/list_result.rb', line 13

def initialize(data)
  @machines = []
  data.each do |machine|
    item = ListResultItem.new(machine)
    @machines << item
  end
end

Instance Attribute Details

#machinesArray<ListResultItem>

Returns The list of machines.

Returns:



9
10
11
# File 'lib/vagrant_utm/model/list_result.rb', line 9

def machines
  @machines
end

Instance Method Details

#any?(uuid) ⇒ Boolean

Checks if a machine with the given UUID exists.

Parameters:

  • uuid (String)

    The UUID of the machine.

Returns:

  • (Boolean)


24
25
26
# File 'lib/vagrant_utm/model/list_result.rb', line 24

def any?(uuid)
  @machines.any? { |i| i.uuid == uuid }
end

#find(name: nil, uuid: nil) ⇒ ListResultItem

Finds a machine with the given name or uuid.

Parameters:

  • name (String) (defaults to: nil)

    The name of the machine.

Returns:



31
32
33
34
35
36
37
# File 'lib/vagrant_utm/model/list_result.rb', line 31

def find(name: nil, uuid: nil)
  if name
    @machines.find { |i| i.name == name }
  elsif uuid
    @machines.find { |i| i.uuid == uuid }
  end
end

#lastListResultItem

Return the last machine in the list.

Returns:



41
42
43
# File 'lib/vagrant_utm/model/list_result.rb', line 41

def last
  @machines.last
end