Class: VagrantSpec::MachineFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant_spec/machine_finder.rb

Overview

Convenience methods for discovering machines

env [Vagrant::Environment]

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ MachineFinder

Returns a new instance of MachineFinder.



8
9
10
# File 'lib/vagrant_spec/machine_finder.rb', line 8

def initialize(env)
  @env = env
end

Instance Method Details

#machine(name) ⇒ Object

name [Symbol]

return [Vagrant::Machine]



15
16
17
18
19
20
21
# File 'lib/vagrant_spec/machine_finder.rb', line 15

def machine(name)
  @env.active_machines.each do |m|
    node = @env.machine(*m)
    return node if node.name == name
  end
  nil
end

#machinesObject

Yield active machines

yield [Vagrant::Machine]



26
27
28
# File 'lib/vagrant_spec/machine_finder.rb', line 26

def machines
  @env.active_machines.each { |m| yield @env.machine(*m) }
end

#match_nodes(reg) ⇒ Object

reg [Regexp]

return [Array<Vagrant::Machine>]



33
34
35
36
# File 'lib/vagrant_spec/machine_finder.rb', line 33

def match_nodes(reg)
  @env.active_machines.collect { |m| machine(m[0]) }
      .select { |m| m if reg.match(m.name.to_s) }
end