class BaseChip::InstallMenu

Public Instance Methods

after() click to toggle source
# File lib/base_chip/install_menu.rb, line 31
def after
  if @table.size > 0
    print_table(@table,'=>')
  end
end
before(name) click to toggle source
# File lib/base_chip/install_menu.rb, line 22
def before(name)
  BaseChip.load_environment
  # \@table = []
  # case pattern
  # when /^\/(.*)\/$/ ; @pattern = /#\{$1}/
  # else              ; @pattern = pattern
  # end
  # # exit unless BaseChip.project.blocks
end
plugin(name) click to toggle source
# File lib/base_chip/install_menu.rb, line 57
def plugin(name)
  fault "This feature is soon forthcoming"
end
recipe(name) click to toggle source
# File lib/base_chip/install_menu.rb, line 38
def recipe(name)
  name_a = name.split /:/
 
  fault "Recipe names should be of the format 'author_name:recipe_name'" unless name_a.size == 2 
  begin
    infile = open("http://basechip.com/recipe_code/#{name_a.first}/#{name_a.last}")
  rescue OpenURI::HTTPError
    fault "Recipe '#{name}' could not be found"
  end
  file = "#{BaseChip.root}/base_chip/recipes/#{name_a.last}.rb"
  out = File.open(file,"w")
  out.puts infile.read
  out.close
  infile.close

  puts "Recipe '#{name}' installed as #{file}"
end
tool(name, version=nil) click to toggle source
# File lib/base_chip/install_menu.rb, line 62
def tool(name, version=nil)
  before(name)
  tools = []
  n = name.to_sym
  BaseChip.tools.each do |tool|
    next unless tool.name.to_s == n.to_s
    tools << tool
  end
  unless tools[0]
    puts "Available tools are:"
    ListMenu.new.run_cli(%w{tools --show select_version})
    fault "No tool found named '#{name}'.  Consider installing a recipe to teach basechip how to install '#{name}'"
  end

  versions = []
  tools.each do |tool|
    tool.configure
    if version
      if v = tool.versions[version]
        versions << v
      end
    else
      versions << tool.selected_version
    end
  end
  unless versions[0]
    puts "Available versions for tool '#{name}' are:"
    ListMenu.new.run_cli(['tools', name, '--show', 'available_versions'])
    fault "No version found named '#{version}' for tool '#{name}'."
  end
  puts "Installing version(s) #{versions.map{|v|v.name}.uniq} for tool '#{name}'"
  installed = []
  versions.each do |version|
    next if installed.include? version.name
    installed << version.name
    version.configure
    fault "shared_directory must be specified in project for install locations" unless version.project.shared_directory
    puts   "cd #{version.project.shared_directory}\n#{version.install}"
    system "cd #{version.project.shared_directory}\n#{version.install}"
  end
end