Class: ConfCtl::MachineList

Inherits:
Object
  • Object
show all
Defined in:
lib/confctl/machine_list.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ MachineList

Returns a new instance of MachineList.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):



14
15
16
17
# File 'lib/confctl/machine_list.rb', line 14

def initialize(opts = {})
  @opts = opts
  @machines = opts[:machines] || parse(extract)
end

Class Method Details

.from_machine(machine) ⇒ MachineList

Parameters:

Returns:



7
8
9
# File 'lib/confctl/machine_list.rb', line 7

def self.from_machine(machine)
  new(machines: { machine.name => machine })
end

Instance Method Details

#[](host) ⇒ Object

Parameters:

  • host (String)


71
72
73
# File 'lib/confctl/machine_list.rb', line 71

def [](host)
  @machines[host]
end

#any?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/confctl/machine_list.rb', line 89

def any?
  !empty?
end

#each {|host, machine| ... } ⇒ Object

Yield Parameters:



21
22
23
# File 'lib/confctl/machine_list.rb', line 21

def each(&)
  machines.each(&)
end

#each_key {|host| ... } ⇒ Object

Yield Parameters:

  • host (String)


26
27
28
# File 'lib/confctl/machine_list.rb', line 26

def each_key(&)
  machines.each_key(&)
end

#each_value {|machine| ... } ⇒ Object

Yield Parameters:



31
32
33
# File 'lib/confctl/machine_list.rb', line 31

def each_value(&)
  machines.each_value(&)
end

#empty?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/confctl/machine_list.rb', line 85

def empty?
  @machines.empty?
end

#firstMachine?

Returns:



76
77
78
# File 'lib/confctl/machine_list.rb', line 76

def first
  @machines.each_value.first
end

#health_checksArray<HealthChecks::Base>

Returns:



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/confctl/machine_list.rb', line 94

def health_checks
  checks = []

  machines.each_value do |machine|
    next if machine.carried?

    checks.concat(machine.health_checks)
  end

  checks
end

#lengthInteger

Returns:

  • (Integer)


81
82
83
# File 'lib/confctl/machine_list.rb', line 81

def length
  @machines.length
end

#managedMachineList

Returns:



56
57
58
# File 'lib/confctl/machine_list.rb', line 56

def managed
  select { |_host, machine| machine.managed }
end

#map {|host, machine| ... } ⇒ Array

Yield Parameters:

Returns:

  • (Array)


45
46
47
# File 'lib/confctl/machine_list.rb', line 45

def map(&)
  machines.map(&)
end

#runnableMachineList

Returns:



66
67
68
# File 'lib/confctl/machine_list.rb', line 66

def runnable
  select { |_host, machine| !machine.carried? && machine.target_host }
end

#select {|host, machine| ... } ⇒ MachineList

Yield Parameters:

Returns:



38
39
40
# File 'lib/confctl/machine_list.rb', line 38

def select(&)
  self.class.new(machines: machines.select(&))
end

#transform_values {|machine| ... } ⇒ Hash

Yield Parameters:

Returns:

  • (Hash)


51
52
53
# File 'lib/confctl/machine_list.rb', line 51

def transform_values(&)
  machines.transform_values(&)
end

#unmanagedMachineList

Returns:



61
62
63
# File 'lib/confctl/machine_list.rb', line 61

def unmanaged
  select { |_host, machine| !machine.managed }
end