Class: ConfCtl::MachineList
- Inherits:
-
Object
- Object
- ConfCtl::MachineList
- Defined in:
- lib/confctl/machine_list.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](host) ⇒ Object
- #any? ⇒ Boolean
- #each {|host, machine| ... } ⇒ Object
- #each_key {|host| ... } ⇒ Object
- #each_value {|machine| ... } ⇒ Object
- #empty? ⇒ Boolean
- #first ⇒ Machine?
- #health_checks ⇒ Array<HealthChecks::Base>
-
#initialize(opts = {}) ⇒ MachineList
constructor
A new instance of MachineList.
- #length ⇒ Integer
- #managed ⇒ MachineList
- #map {|host, machine| ... } ⇒ Array
- #runnable ⇒ MachineList
- #select {|host, machine| ... } ⇒ MachineList
- #transform_values {|machine| ... } ⇒ Hash
- #unmanaged ⇒ MachineList
Constructor Details
#initialize(opts = {}) ⇒ MachineList
Returns a new instance of MachineList.
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
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
71 72 73 |
# File 'lib/confctl/machine_list.rb', line 71 def [](host) @machines[host] end |
#any? ⇒ Boolean
89 90 91 |
# File 'lib/confctl/machine_list.rb', line 89 def any? !empty? end |
#each {|host, machine| ... } ⇒ Object
21 22 23 |
# File 'lib/confctl/machine_list.rb', line 21 def each(&) machines.each(&) end |
#each_key {|host| ... } ⇒ Object
26 27 28 |
# File 'lib/confctl/machine_list.rb', line 26 def each_key(&) machines.each_key(&) end |
#each_value {|machine| ... } ⇒ Object
31 32 33 |
# File 'lib/confctl/machine_list.rb', line 31 def each_value(&) machines.each_value(&) end |
#empty? ⇒ Boolean
85 86 87 |
# File 'lib/confctl/machine_list.rb', line 85 def empty? @machines.empty? end |
#first ⇒ Machine?
76 77 78 |
# File 'lib/confctl/machine_list.rb', line 76 def first @machines.each_value.first end |
#health_checks ⇒ Array<HealthChecks::Base>
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 |
#length ⇒ Integer
81 82 83 |
# File 'lib/confctl/machine_list.rb', line 81 def length @machines.length end |
#managed ⇒ MachineList
56 57 58 |
# File 'lib/confctl/machine_list.rb', line 56 def managed select { |_host, machine| machine.managed } end |
#map {|host, machine| ... } ⇒ Array
45 46 47 |
# File 'lib/confctl/machine_list.rb', line 45 def map(&) machines.map(&) end |
#runnable ⇒ MachineList
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
38 39 40 |
# File 'lib/confctl/machine_list.rb', line 38 def select(&) self.class.new(machines: machines.select(&)) end |
#transform_values {|machine| ... } ⇒ Hash
51 52 53 |
# File 'lib/confctl/machine_list.rb', line 51 def transform_values(&) machines.transform_values(&) end |
#unmanaged ⇒ MachineList
61 62 63 |
# File 'lib/confctl/machine_list.rb', line 61 def unmanaged select { |_host, machine| !machine.managed } end |