module CFMicro

Public Class Methods

config_file(file) click to toggle source
# File lib/micro/micro.rb, line 5
def config_file(file)
  File.expand_path("../../../../config/#{file}", __FILE__)
end
escape_path(path) click to toggle source
# 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) click to toggle source
# 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) { || ... } click to toggle source
# 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

Private Instance Methods

config_file(file) click to toggle source
# File lib/micro/micro.rb, line 5
def config_file(file)
  File.expand_path("../../../../config/#{file}", __FILE__)
end
escape_path(path) click to toggle source
# 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) click to toggle source
# 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) { || ... } click to toggle source
# 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