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)


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

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

#any?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/confctl/machine_list.rb', line 78

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)


74
75
76
# File 'lib/confctl/machine_list.rb', line 74

def empty?
  @machines.empty?
end

#firstMachine?

Returns:



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

def first
  @machines.each_value.first
end

#health_checksArray<HealthChecks::Base>

Returns:



83
84
85
86
87
88
89
90
91
# File 'lib/confctl/machine_list.rb', line 83

def health_checks
  checks = []

  machines.each_value do |machine|
    checks.concat(machine.health_checks)
  end

  checks
end

#lengthInteger

Returns:

  • (Integer)


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

def length
  @machines.length
end

#managedMachineList

Returns:



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

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

#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

#unmanagedMachineList

Returns:



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

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