Module: CFMicro

Defined in:
lib/micro/micro.rb,
lib/micro/vmrun.rb,
lib/micro/errors.rb,
lib/micro/plugin.rb

Defined Under Namespace

Modules: Switcher Classes: MCFError, McfCommand, VMrun

Class Method Summary collapse

Class Method Details

.config_file(file) ⇒ Object



5
6
7
# File 'lib/micro/micro.rb', line 5

def config_file(file)
  File.expand_path("../../../../config/#{file}", __FILE__)
end

.escape_path(path) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/micro/micro.rb', line 9

def escape_path(path)
  path = File.expand_path(path)
  if RUBY_PLATFORM =~ /mingw|mswin32|cygwin/
    if path.include?(' ')
      '"' + path + '"'
    else
      path
    end
  else
    path.gsub(' ', '\ ')
  end
end

.locate_file(file, directory, search_paths) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/micro/micro.rb', line 22

def locate_file(file, directory, search_paths)
  search_paths.each do |path|
    expanded_path = File.expand_path(path)
    next unless File.exists?(expanded_path)
    Find.find(expanded_path) do |current|
      if File.directory?(current) && current.include?(directory)
        full_path = File.join(current, file)
        return escape_path(full_path) if File.exists?(full_path)
      end
    end
  end

  false
end

.run_command(command, args = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/micro/micro.rb', line 37

def run_command(command, args=nil)
  # TODO switch to using posix-spawn instead
  result = %x{#{command} #{args} 2>&1}
  if $?.exitstatus == 0
    result.split(/\n/)
  else
    if block_given?
      yield
    else
      raise CFMicro::MCFError, "failed to execute #{command} #{args}:\n#{result}"
    end
  end
end