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
- #select {|host, machine| ... } ⇒ MachineList
- #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
60 61 62 |
# File 'lib/confctl/machine_list.rb', line 60 def [](host) @machines[host] end |
#any? ⇒ Boolean
78 79 80 |
# File 'lib/confctl/machine_list.rb', line 78 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
74 75 76 |
# File 'lib/confctl/machine_list.rb', line 74 def empty? @machines.empty? end |
#first ⇒ Machine?
65 66 67 |
# File 'lib/confctl/machine_list.rb', line 65 def first @machines.each_value.first end |
#health_checks ⇒ Array<HealthChecks::Base>
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 |
#length ⇒ Integer
70 71 72 |
# File 'lib/confctl/machine_list.rb', line 70 def length @machines.length end |
#managed ⇒ MachineList
50 51 52 |
# File 'lib/confctl/machine_list.rb', line 50 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 |
#select {|host, machine| ... } ⇒ MachineList
38 39 40 |
# File 'lib/confctl/machine_list.rb', line 38 def select(&) self.class.new(machines: machines.select(&)) end |
#unmanaged ⇒ MachineList
55 56 57 |
# File 'lib/confctl/machine_list.rb', line 55 def unmanaged select { |_host, machine| !machine.managed } end |